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 HabalcikRank #902 · 2.3K reputationPosted Jan 28, 2015, 4:14 AM EST
try setting the connection before you start reading.
com.Connection = con;
Suraj SahooRank #382 · 6.6K reputationPosted Jan 28, 2015, 4:06 AM EST
What is the exact exception that is arising?
Thanks
Ranjit PowarRank #553 · 4.4K reputationPosted Jan 28, 2015, 4:30 AM EST
SqlCommand com=new SqlCommand("SELECT TOP 1 Mojodi FROM TMojojdi ORDER BY Id DESC",con);
ghasem dehRank #8,160 · 227 reputationPosted Jan 28, 2015, 4:28 AM EST