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();