我的用户活动日志中有问题。在SQL中,我将用户的UserID放在User_Activity_Log中,但是当我运行代码时,该UserID始终显示0作为UserID。
string Login = "Login";
Main code = new Main();
string SqlUserID = "SELECT UserID FROM tblUser WHERE Username='" + Convert.ToString(bunifuMaterialTextbox1.Text) + "'AND Password'" + Convert.ToString(bunifuMaterialTextbox2.Text) + "'";
UserID = code.Converter_string(SqlUserID).ToString();
if (UserID != "")
{
string SqlLoginName = "SELECT Username FROM tblUser WHERE UserID='" + Convert.ToString(UserID) + "'";
username = code.Converter_string(SqlLoginName).ToString();
code.Execute(@"INSERT INTO User_Activity_Log VALUES('" + Convert.ToString(bunifuMaterialTextbox1.Text) + "','" + UserID + "','" + DateTime.Now + "','" + Login + "','" + CIP + "')");
menu fr = new menu();
this.Hide();
fr.Show();
}
在我的转换器字符串中找到我的代码
public string Converter_string(string SQL)
{
try
{
SqlConnection con = Main.getConnection();
DataTable consultanttable = new DataTable();
string StringConsultant;
SqlDataAdapter Consultantdataadapter = new SqlDataAdapter(SQL, con);
Consultantdataadapter.Fill(consultanttable);
foreach(DataRow myrow in consultanttable.Rows)
{
StringConsultant = Convert.ToString(myrow[0]);
return StringConsultant;
}
}
catch
{
System.Windows.MessageBox.Show("Successfully Login");
}
return "0";
}