更新数据库??
更新数据库,出现错误提示“将截断字符串或二进制数据。语句已中止”。gridview1中包含commandfield,利用该按钮列进行更新操作。
源代码如下:
public void UpdateRecord( object sender,GridViewUpdateEventArgs e )
{
if (Page.IsValid)
{
//提取数据
int index = e.RowIndex;
ObjConnection = new SqlConnection(strConnection);
ObjCommand = new SqlCommand(SQL_Statement,ObjConnection);
ObjAdapter = new SqlDataAdapter(ObjCommand);
cb = new SqlCommandBuilder(ObjAdapter);
DataSet Temporary_DataSet = new DataSet();
ObjAdapter.Fill(Temporary_DataSet);
TextBox AddressTextBox = (TextBox)GridView1.Rows[index].Cells[0].Controls[0];
string temp_Address = AddressTextBox.Text.Trim();
TextBox DemoTextBox = (TextBox)GridView1.Rows[index].Cells[1].Controls[0];
string temp_Demo = DemoTextBox.Text.Trim();
DataTable Temporary_DataTable=Temporary_DataSet.Tables[0];
Temporary_DataTable.PrimaryKey=new DataColumn[]{Temporary_DataTable.Columns[0]};
DataRow r=Temporary_DataTable.Rows.Find( GridView1.Rows[index].Cells[0].Text );
r["Address"] =temp_Address ;
r["Demo"] = temp_Demo;
//
ObjAdapter.Update(Temporary_DataSet);
ObjConnection.Close();
ObjAdapter.Dispose();
ObjCommand.Dispose();
ObjConnection.Dispose();
GridView1.EditIndex = -1;
Binding();//重新绑定数据源
}
堆栈跟踪:
[SqlException (0x80131904): 将截断字符串或二进制数据。
语句已终止。]
System.(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +1455816
System.(RowUpdatedEventArgs rowUpdatedEvent, BatchCommandInfo[] batchCommands, Int32 commandCount) +41
System.(DataRow[] dataRows, DataTableMapping tableMapping) +2037
System.(DataTable dataTable, DataTableMapping tableMapping) +40
System.(DataSet dataSet, String srcTable) +183
System.(DataSet dataSet) +12
Estate_Information_Management.UpdateRecord(Object sender, GridViewUpdateEventArgs e) in c:\Inetpub\wwwroot\House\Default.aspx.cs:170
System.Web.UI.WebControls.GridView.OnRowUpdating(GridViewUpdateEventArgs e) +133
System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +776
System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +837
System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +117
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +35
System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +115
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +163
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1746
另外,数据库中Demo字段数据类型为ntext,Address字段数据类型为nvarchar(MAX)。
希望广大网友帮忙解决,谢谢!!