我使用的WinForms C#获得用户ID的WinForms C#
我试图从用户信息表中获取用户ID,然后插入另一台为这一点,用户ID首先,我尝试这
更新的代码
OK我尝试这个
public class Login
{
string email;
string password;
public int userid;
public Login(string UserEmail, string UserPassword)
{
email = UserEmail;
password = UserPassword;
}
public string Logined()
{
con.Open();
cmd = new SqlCommand("SELECT userid from UserInformation WHERE UserEmail='" + email + "'and UserPassword='" + password + "'", con);
cmd.Parameters.AddWithValue("@UserEmail", email);
cmd.Parameters.AddWithValue("@UserPassword", password);
cmd.ExecuteNonQuery();
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Categorys obj = new Categorys();
obj.ShowDialog();
while (dr.Read())
{
userid = Convert.ToInt32(dr["userid"]);
}
return msg = "You Are Successfully Login!";
}
else
{
return msg = "Sorry Incorrect Password Or Email!";
}
}
这为您button_click否则,如果
else if (comboBox1.Text == "Admin.")
{
this.Hide();
string UserEmail = textBox2.Text;
string UserPassword = textBox1.Text;
Login objlogin = new Login(UserEmail, UserPassword);
textBox3.Text = Convert.ToString(objlogin.userid);
MessageBox.Show(objlogin.Logined());
savedid = objlogin.userid;
Categorys obj = new Categorys();
obj.ShowDialog();
con.Close();
}
,并在新的形式,我试试这件形式负载呼叫ID
private void Categorys_Load(object sender, EventArgs e)
{
Login_Form l = new Login_Form();
textBox2.Text = Convert.ToString(l.savedid);
}
但这显示0中的文本框
无论用它在onload方法的其他任何,请阅读[SQL注入](http://stackoverflow.com/search?q=sql+injection+%5B.net%5D)以及如何防止它和[如何将密码存储在数据库中](http ://stackoverflow.com/search q =商店+密码+在+数据库+%5B.net%5D)。 –