通过表单传递自动递增的id

时间:2017-03-15 10:55:43

标签: c# sql-server

我正在尝试使用SQLServer数据库进行简单登录,并且我想知道在确认工作后如何传递user_id。

private void login_button_Click(object sender, EventArgs e)
    {
        SqlConnection con=new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='D:\Visual Studio\Test 3\Database\users.mdf';Integrated Security=True;Connect Timeout=30");
        String sqlquery = "select username,password from user_creds where username='"+username.Text+"' and password='"+pass.Text+"'";

        SqlDataAdapter adp = new SqlDataAdapter(sqlquery, con);
        DataSet ds = new DataSet();

        adp.Fill(ds);

        DataTable dt = ds.Tables[0];

        if (dt.Rows.Count >=1)
        {
            home fl = new home();
            this.Hide();
            fl.Show();
        }

        else
        {
            MessageBox.Show("Invalid login credentials.");
        }

0 个答案:

没有答案