Click here to Skip to main content
15,888,273 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can any one tell me why it showing this error to me in this code
C#
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();

it showing me error for dt.Load(dr); line

ERROR:Conversion failed when converting the varchar value '311/3' to data type int.

I have define c_SerialNo as varchar(50) in my database.
Posted
Updated 21-Aug-13 1:12am
v2

1 solution

Hi Rakhil,

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


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


I hope this will help you, Let me know.
 
Share this answer
 
Comments
Mohan Gopi 21-Aug-13 6:48am    
it's working or not
Rakhil Naik 21-Aug-13 6:48am    
its working thanks alot
Sadique KT 21-Aug-13 7:18am    
Mark as answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900