错误:将varchar值'311/3'转换为数据类型int时转换失败。 [英] ERROR:Conversion failed when converting the varchar value '311/3' to data type int.

查看:112
本文介绍了错误:将varchar值'311/3'转换为数据类型int时转换失败。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

任何人都可以告诉我为什么在这段代码中向我显示这个错误

Can any one tell me why it showing this error to me in this code

String SrNo = cSerialNo.Text;
          String SrNumber;
          string s = System.Configuration.ConfigurationSettings.AppSettings.Get("Conn");
          SqlConnection connection = new SqlConnection(s);
          connection.Open();
          SqlCommand cmd = new SqlCommand();
          cmd.Connection = connection;
          cmd.CommandText = ("SELECT c_SerialNo FROM Cultivator_tbl WHERE c_SerialNo=" +SrNo);
          SqlDataReader dr = cmd.ExecuteReader();
          DataTable dt = new DataTable();
          dt.Load(dr);//Error here
          cSerialNo.Text = dt.Rows[0][0].ToString();
          SrNumber = dt.Rows[0][0].ToString();
          if (SrNumber != "")
          {
              MessageBox.Show("SERIAL NO\t" + SrNumber + "\t ALREADY EXISTS");
          }
          connection.Close();



它显示我dt.Load(dr)的错误; line



错误:将varchar值'311/3'转换为数据类型int时转换失败。



我在我的数据库中将 c_SerialNo 定义为 varchar(50)

推荐答案

您好Rakhil,



i找到您在此系列中遗漏的内容,请尝试替换下面的行你的代码。





Hi Rakhil,

i find what you have missed in this Line, try and replace the below line in your code.


cmd.CommandText = ("SELECT c_SerialNo FROM Cultivator_tbl WHERE c_SerialNo= '" +SrNo +"'");





我希望这会对你有所帮助,请告诉我。



I hope this will help you, Let me know.


这篇关于错误:将varchar值'311/3'转换为数据类型int时转换失败。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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