4
Answers

What is the cause of the error ?

ghasem deh

ghasem deh

9y
591
1
i want to read the data table and the previous value of a field, the value I add ...
But it gives the following error:
In relation to the connection ! 
 
http://s4.picofile.com/file/8166859342/1errror_mojodi.jpg 
 
i use this code :
 
 int a = 0;
            try
            {
                SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Shopping;Integrated Security=True");
                SqlCommand com = new SqlCommand();
                com.CommandText = "SELECT TOP 1 Mojodi FROM TMojojdi ORDER BY Id DESC";
                con.Open();
                SqlDataReader dr = com.ExecuteReader();
                if (dr.Read())
                {
                    a = Int32.Parse(dr[0].ToString());
                }
                con.Close();
            }
            catch
            {

            }
 
 

Answers (4)