this is my table
rate total time date
2.666541 0015744 16:17:37 16-05-08
i can wrote code like this for retreving
SqlConnection con = new SqlConnection("server=localhost;initial catalog=online_application1;user id=sa;pwd=");con.Open();
string st = "select total from packet where date="
+ date + " "; DataSet ds = new DataSet(); DataRow dr; DataTable dt; SqlDataAdapter da = new SqlDataAdapter(st, con);da.Fill(ds,
"packet");dt = ds.Tables[0];
recptr = dt.Rows.Count - 1;
dr = dt.Rows[recptr];
string yes = dr1[0].ToString();
i want retrive data from above table where date=16-05-08
but i getting this error
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code
Additional information: Syntax error converting the varchar value '14-05-08' to a column of data type int.
plz help ...or any other method to retrive data
jeevan mummadiPosted May 19, 2008, 4:33 AM
still i getting error manish,
i try for this code also
DateTime yesterday = DateTime.Today.AddMinutes(-2180); DateTime today = DateTime.Today.AddMinutes(360); string strdata = yesterday.ToString("dd-MM-yy,hh:mm"); string date = strdata.Substring(0, 8); string time = strdata.Substring(9, 5); string strtdy = today.ToString("dd/MM/yy,hh:mm:ss"); string datetdy = strtdy.Substring(0, 8); string timetdy = strtdy.Substring(9, 8); string st1 = "select total from packet where date='" + date + "'"; SqlCommand cmd = new SqlCommand(st1, con); SqlDataReader dre1 = cmd.ExecuteReader(); string yes = dre1.GetString(0);i getting this error
An exception of type 'System.InvalidOperationException' occurred in System.Data.dll but was not handled in user code
Additional information: Invalid attempt to read when no data is present.
con.Close();
Blocked AccountPosted May 19, 2008, 4:12 AM
Write your query like this and then try. I think data type of date field is varchar of your table.
string st = "select total from packet where date='" + date + "'";