[英]trying to add value into a checkbox
Hi guys i'm trying to get the compiler to get the information the checkbox checked from the database but couldn't do it how can i add value into the checkbox exactly, please check attempt of doing so.大家好,我正在尝试让编译器从数据库中获取复选框检查的信息,但无法做到这一点我如何才能准确地将值添加到复选框中,请检查这样做的尝试。 i need your help guys thanks..
我需要你们的帮助谢谢..
string query = "SELECT count (1) FROM Login WHERE Username=@Username AND password=@password AND usertype=@usertype";
SqlCommand sqlCmd = new SqlCommand(query, sqlCon);
sqlCmd.CommandType = CommandType.Text;
sqlCmd.Parameters.AddWithValue("@Username", txtUsername.Text);
sqlCmd.Parameters.AddWithValue("@password", txtPassword.Text);
sqlCmd.Parameters.AddWithValue("@usertype",checkbox1);/// how can i add values into checkbox !
sqlCmd.Parameters.AddWithValue("@usertype", checkbox2);
int count = Convert.ToInt32(sqlCmd.ExecuteScalar());
if (count == 1)
{
if ((bool)checkbox1.IsChecked == true)
{
MainWindow Dashboard = new MainWindow();
Dashboard.Show();
MessageBox.Show("You'r logged in as an Admin");
this.Close();
}
if ((bool)checkbox2.IsChecked == true)
{
;
Student stu = new Student();
stu.Show();
MessageBox.Show("You'r logged in as a Student");
this.Close();
}
You could check whether a CheckBox
is checked and then set the value of the parameter, for example to the Content
of the checked CheckBox
:您可以检查
CheckBox
是否被选中,然后设置参数的值,例如检查CheckBox
的Content
:
if (checkbox1.IsChecked == true)
sqlCmd.Parameters.AddWithValue("@usertype", checkbox1.Content.ToString());
else if (checkbox2.IsChecked == true)
sqlCmd.Parameters.AddWithValue("@usertype", checkbox2.Content.ToString());
But if you require the @usertype
parameter to be set, you should use radio buttons rather than check boxes.但是如果你需要设置
@usertype
参数,你应该使用单选按钮而不是复选框。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.