登陆界面里有两个textbox用来输用户名密码,现在我想选radiobutton1的时候判断用户名密码的同时在判断一下对应用户名的RID是否为1
这是登陆按钮里的
                string strConn = "Server=.; Database=db;uid=sa;pwd=;";
                string strCmd = "select  count(*)  from  [user]  where  username  =  '" + textBox1.Text + "'  and  userpwd = '" + textBox2.Text + "'";
                SqlConnection myConnection = new SqlConnection();
                myConnection.ConnectionString = strConn;
                SqlCommand myCommand = new SqlCommand(strCmd, myConnection);
                myCommand.Connection.Open();
                int flag = System.Convert.ToInt32(myCommand.ExecuteScalar());
                myCommand.Connection.Close();
                if (flag > 0)
                {MessageBox.Show("登陆成功");}
想问下选radiobutton1的时候怎么判断RID是否为1,应该写在哪

解决方案 »

  1.   

    你应该有一个登陆Button把?
    在这个  登陆Button的 click里写private void button_click(object sender ,eventArgs e)
    {
                      string strConn = "Server=.; Database=db;uid=sa;pwd=;"; 
                     string strCmd =string.empty;
                    if(!radiobutton1.checked)
                    {
                         strCmd = "select  count(*)  from  [user]  where  username  =  '" + textBox1.Text + "'
                          and  userpwd = '" + textBox2.Text + "'"; 
                     }
                     else
                     {
                         strCmd = "select  count(*)  from  [user]  where  username  =  '" + textBox1.Text + "'
                          and  userpwd = '" + textBox2.Text + "' And RID='1' "; 
                     }
     
                   
                    SqlConnection myConnection = new SqlConnection(); 
                    myConnection.ConnectionString = strConn; 
                    SqlCommand myCommand = new SqlCommand(strCmd, myConnection); 
                    myCommand.Connection.Open(); 
                    int flag = System.Convert.ToInt32(myCommand.ExecuteScalar()); 
                    myCommand.Connection.Close(); 
                    if (flag > 0) 
                    {MessageBox.Show("登陆成功");} 
    }
      

  2.   

    我的意思是,用户表了有username userpwd RID 3列
    登陆界面有2个textbox和1个radiobutton
    登陆时选中radiobutton在按登录按钮,不关要判断用户名密码,还要判断此用户名对应的RID为1
    那段代码是登陆按钮里的,求助选中radiobutton后如何判断RID为1