我正在使用LINQTOSQL类来插入,更新等操作,这是将数据操作任务从Web应用程序处理到数据库所必需的。
这里我的web应用程序出现了从linqtosql类插入和更新时间错误的问题。
这里是:
Server Error in '/EasyMail_New' Application.
Could not translate expression 'value(DataClassesDataContext).UpdateEmailField(2, "TotalFileSize", "0")' into SQL and could not treat it as a local expression.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.InvalidOperationException: Could not translate expression 'value(DataClassesDataContext).UpdateEmailField(2, "TotalFileSize", "0")' into SQL and could not treat it as a local expression.
Source Error:
Line 397: public object UpdateEmailField([global::System.Data.Linq.Mapping.ParameterAttribute(Name="Email_id", DbType="Int")] System.Nullable<int> email_id, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(25)")] string var_name, [global::System.Data.Linq.Mapping.ParameterAttribute(DbType="VarChar(100)")] string var_value)
Line 398: {
Line 399: return ((object)(this.ExecuteMethodCall(this, ((MethodInfo)(MethodInfo.GetCurrentMethod())), email_id, var_name, var_value).ReturnValue));
Line 400: }
Line 401:
Source File: e:\Shalin\WorkMaterial\EasyMail_New\App_Code\DataClasses.designer.cs Line: 399
Stack Trace:
[InvalidOperationException: Could not translate expression 'value(DataClassesDataContext).UpdateEmailField(2, "TotalFileSize", "0")' into SQL and could not treat it as a local expression.]
System.Data.Linq.SqlClient.Generator.Generate(SqlNode node, LocalBuilder locInstance) +637618
System.Data.Linq.SqlClient.Generator.GenerateBody(ILGenerator generator, SqlExpression expression) +276
System.Data.Linq.SqlClient.ObjectReaderCompiler.CompileDynamicMethod(Generator gen, SqlExpression expression, Type elementType) +188
System.Data.Linq.SqlClient.ObjectReaderCompiler.Compile(SqlExpression expression, Type elementType) +367
System.Data.Linq.SqlClient.SqlProvider.GetReaderFactory(SqlNode node, Type elemType) +100
System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query) +253
System.Data.Linq.DataContext.ExecuteMethodCall(Object instance, MethodInfo methodInfo, Object[] parameters) +83
DataClassesDataContext.UpdateEmailField(Nullable`1 email_id, String var_name, String var_value) in e:\Shalin\WorkMaterial\EasyMail_New\App_Code\DataClasses.designer.cs:399
_Default.submit_Click(Object sender, EventArgs e) in e:\Shalin\WorkMaterial\EasyMail_New\Mail.aspx.cs:1309
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +118
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +112
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5563
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
我只是用Google搜索并试图解决这个问题。但没有成功。是他们可以解决我的问题吗。
请帮助我...... -------------------Update--------------------
ALTER PROCEDURE [dbo].[UpdateEmailField]
(
@Email_id int,
@var_name varchar(25),
@var_value varchar(100)
)
AS
BEGIN
SET NOCOUNT ON;
IF @var_name = 'Title'
UPDATE [EASYMAIL].[dbo].[tbl_Email_master] SET [Title] = CAST(@var_value AS TEXT) WHERE (Id=@Email_id)
ELSE IF @var_name = 'Body'
UPDATE [EASYMAIL].[dbo].[tbl_Email_master] SET [Body] = CAST(@var_value AS TEXT) WHERE (Id=@Email_id)
ELSE IF @var_name = 'ToUser'
UPDATE [EASYMAIL].[dbo].[tbl_Email_master] SET [ToUser] = CAST(@var_value AS TEXT) WHERE (Id=@Email_id)
ELSE IF @var_name = 'IsFileAttached'
UPDATE [EASYMAIL].[dbo].[tbl_Email_master] SET [IsFileAttached] = CAST(@var_value AS BIT) WHERE (Id = @Email_id)
ELSE IF @var_name = 'SentDateTime'
UPDATE [EASYMAIL].[dbo].[tbl_Email_master] SET [SentDateTime] = CAST(@var_value AS DATETIME) WHERE (Id = @Email_id)
ELSE IF @var_name = 'TotalFileSize'
UPDATE [EASYMAIL].[dbo].[tbl_Email_master] SET [TotalFileSize] = CAST (@var_value AS BIGINT) WHERE (Id=@Email_id)
END