转换失败 [英] conversion failed

查看:94
本文介绍了转换失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  SqlCommand delcmd = new SqlCommand();

                         delcmd.CommandText =" DELETE FROM add_investor WHERE investor_cnic =" + dataGridView1.SelectedRows [0] .Cells [0] .Value.ToString()
+"" ;;

                         my.Open();&
                         delcmd.Connection = my;

                         delcmd.ExecuteNonQuery();

                         my.Close();

                         dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows [0] .Index);

                         my.Close();

 SqlCommand delcmd = new SqlCommand();
                        delcmd.CommandText = "DELETE FROM add_investor WHERE investor_cnic=" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + "";
                        my.Open();
                        delcmd.Connection = my;
                        delcmd.ExecuteNonQuery();
                        my.Close();
                        dataGridView1.Rows.RemoveAt(dataGridView1.SelectedRows[0].Index);
                        my.Close();

将nvarchar值'34101-1212121-1'转换为数据类型int时转换失败。

Conversion failed when converting the nvarchar value '34101-1212121-1' to data type int.

什么是错的

推荐答案

显然,datagrid列的值是'34101-1212121-1',显然可以不能转换为整数(例如1或10)。
Apparently the value of the datagrid column is '34101-1212121-1', which obviously can't be converted to an integer (such as 1 or 10).


这篇关于转换失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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