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
{
}

Michal HabalcikPosted Jan 28, 2015, 9:14 AM
try setting the connection before you start reading.
com.Connection = con;
Ranjit PowarPosted Jan 28, 2015, 9:30 AM
SqlCommand com=new SqlCommand("SELECT TOP 1 Mojodi FROM TMojojdi ORDER BY Id DESC",con);
ghasem dehPosted Jan 28, 2015, 9:28 AM
Suraj SahooPosted Jan 28, 2015, 9:06 AM
What is the exact exception that is arising?
Thanks