0
ログアウトボタンを押すたびにこのエラーが発生する System.Data.SqlClient.SqlException:文字列から日付または時刻を変換するときに変換に失敗しました。文字列から日付および/または時刻を変換するときに変換に失敗しました。 System.Data.SqlClient.SqlException:
このマイコーディングパート。助けて。
SqlConnection conlog = new SqlConnection(ConfigurationManager.ConnectionStrings["loginConnectionString"].ConnectionString);
conlog.Open();
Session["New"] = null;
string logintime = "select LoginTime from Logindata where UserName ='" + Label1.Text + "'";
SqlCommand logintimequery = new SqlCommand(logintime, conlog);
int logintimestr = logintimequery.ExecuteNonQuery();
string idQuery = "Select ID from [Table] where Username='"+Label1.Text+"'";
SqlCommand idd = new SqlCommand(idQuery, conlog);
string strQuery = "update logindata set LogoutTime='" + DateTime.Now + "' where LoginTime='"+logintimestr+ "' and UserName='" + Label1.Text + "' ";
SqlCommand cmd = new SqlCommand(strQuery, conlog);
cmd.Parameters.AddWithValue("@uname", Label1.Text);
cmd.Parameters.AddWithValue("@logouttime", DateTime.Now.ToString());
cmd.ExecuteNonQuery();
Response.Redirect("Loginform.aspx");
conlog.Close();