| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 594 人关注过本帖
标题:更新数据库??
只看楼主 加入收藏
jdlichao
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-8-10
收藏
 问题点数:0 回复次数:2 
更新数据库??
更新数据库,出现错误提示“将截断字符串或二进制数据。语句已中止”。

  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)。

希望广大网友帮忙解决,谢谢!!
搜索更多相关主题的帖子: 数据库 
2008-08-12 13:14
hw1024
Rank: 1
等 级:新手上路
帖 子:35
专家分:0
注 册:2008-3-11
收藏
得分:0 
c# 技术交流群:64913828
有问题大家讨论
2008-08-12 13:19
jdlichao
Rank: 1
等 级:新手上路
帖 子:9
专家分:0
注 册:2008-8-10
收藏
得分:0 
谢谢
谢谢!
2008-08-12 13:40
快速回复:更新数据库??
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.011827 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved