现在我试图用C#窗口窗体桌面应用程序获取用户日志.
我试过了
private void btn_Login_Click(object sender, EventArgs e)
{
string username = txt_Username.Text;
string password = txt_Password.Text;
if (username=="" && password=="")
{
MessageBox.Show("Please enter Username and Password");
}
else
{
Function.sqlfunction.connection.Open();
string query = "adminlogin";
SqlCommand cmd = new SqlCommand(query, Function.sqlfunction.connection);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@username", username);
cmd.Parameters.AddWithValue("@pass_word", password);
int usercount = (Int32)cmd.ExecuteScalar();
if (usercount == 1)
{
string loginsert = "INSERT INTO tbl_loguser (username, loginTime) VALUES (@username,@time)";
SqlCommand logcmd = new SqlCommand(loginsert, Function.sqlfunction.connection);
logcmd.CommandType = CommandType.Text;
logcmd.Parameters.AddWithValue("@username", username);
logcmd.Parameters.AddWithValue("@time", DateTime.Now.ToString()); …Run Code Online (Sandbox Code Playgroud)