小编myd*_*nan的帖子

使用C#窗口表单应用程序在用户登录期间保存登录时间

现在我试图用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)

c# sqlclient winforms

2
推荐指数
1
解决办法
1345
查看次数

标签 统计

c# ×1

sqlclient ×1

winforms ×1