Windows表单字符串或二进制数据将被截断。调试后语句已终止。错误 [英] windows form String or binary data would be truncated. The statement has been terminated.error after debug

查看:70
本文介绍了Windows表单字符串或二进制数据将被截断。调试后语句已终止。错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   void  Update_Click(对象发​​件人,EventArgs e)
{
for int i = 0 ; i < dataGridView2.RowCount - 1 ; i ++)
{
string sql = UPDATE [SAPProduction]。[ProductionData] SET + Jobcard =' + dataGridView2.Rows [i] .Cells [ Jobcard ] .ToString()+ ', + Planqty =' + dataGridView2。行[i] .Cells [ Planqty]。ToString()+ ', +
Mouldqty =' + dataGridView2.Rows [i] .Cells [ Mouldqty ]。ToString()+ ', +
Operator =' + dataGridView2.Rows [i] .Cells [ 运算符]。ToString()+ ', +
Supervisor =' + dataGridView2 .Rows [i] .Cells [ Supervisor]。ToString()+ ', +
Profilename =' + dataGridView2.Rows [i]。单元格[ Profilename]。ToString()+ ', +
Process =' + dataGridView2.Rows [i] .Cells [ Process ] .ToString()+ ', +
Date =' + dataGridView2.Rows [i] .Cells [ 日期]。ToString( )+ ', +
备注=' + dataGridView2.Rows [i] .Cells [ 备注]。ToString()+ ', +
Approvedby =' + dataGridView2.Rows [i] .Cells [< span class =code-string> Approvedby]。ToString()+ ', +
Division = ' + dataGridView2.Rows [i] .Cells [ Division]。ToString ()+ +
Od =' + dataGridView2.Rows [i] .Cells [ Od]。ToString()+ +
其中id =' + dataGridView2.CurrentRow.Cells [ id ]。Value.ToString()+ '; // Jobcard =您的愿望行名片ID

SqlCommand cmd = new SqlCommand(sql,objConn1);
objConn1.Open();
cmd.ExecuteNonQuery();
objConn1.Close();
}
}

解决方案

这是由于数据类型不匹配检查数据类型...

Quote:

字符串或二进制数据将被截断。



上述错误告诉数据库中的数据类型小于您尝试插入该列的值。您可以增加数据类型的长度,也可以减少要插入的值的长度。


private void Update_Click(object sender, EventArgs e)
        {
            for (int i = 0; i < dataGridView2.RowCount - 1; i++)
            {
                string sql = "UPDATE [SAPProduction].[ProductionData] SET " + " Jobcard= '" + dataGridView2.Rows[i].Cells["Jobcard"].ToString() + "', " + " Planqty= '" + dataGridView2.Rows[i].Cells["Planqty"].ToString() + "', " +
                                   " Mouldqty = '" + dataGridView2.Rows[i].Cells["Mouldqty"].ToString() + "', " +
                                   " Operator = '" + dataGridView2.Rows[i].Cells["Operator"].ToString() + "', " +
                                   " Supervisor = '" + dataGridView2.Rows[i].Cells["Supervisor"].ToString() + "' , " +
                                   " Profilename ='" + dataGridView2.Rows[i].Cells["Profilename"].ToString() + "' , " +
                                   " Process='" + dataGridView2.Rows[i].Cells["Process"].ToString() + "' , " +
                                   " Date='" + dataGridView2.Rows[i].Cells["Date"].ToString() + "' , " +
                                   " Remark='" + dataGridView2.Rows[i].Cells["Remark"].ToString() + "' , " +
                                   " Approvedby='" + dataGridView2.Rows[i].Cells["Approvedby"].ToString() + "' , " +
                                   " Division='" + dataGridView2.Rows[i].Cells["Division"].ToString() + "' , " +
                                   " Od='" + dataGridView2.Rows[i].Cells["Od"].ToString() + "' " +
                                   " Where id = '" + dataGridView2.CurrentRow.Cells["id"].Value.ToString() + "' "; // Jobcard = your desire Rows Jobcard Id

                SqlCommand cmd = new SqlCommand(sql, objConn1);
                objConn1.Open();
                cmd.ExecuteNonQuery();
                objConn1.Close();
            }
        }

解决方案

This occurs due to datatype mismatches check for the datatype...


Quote:

String or binary data would be truncated.


The above error tells the datatype in database is smaller than the value you are trying to insert into that column. You can either increase the length of the datatype or reduce the length of the value you are trying to insert.


这篇关于Windows表单字符串或二进制数据将被截断。调试后语句已终止。错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆