应用C#+SQLServer,小弟初学者,各位大侠帮帮忙啊

解决方案 »

  1.   

    假设有个按钮,我现在写按钮的单机事件private  Login_Click(Object sender ,EventArgs e)
    {
     SqlConnection con=new SqlConnection("Sever=.,database=Test,UID=sa,PWD=as");
     SqlCommand cmd=new SqlCommand(String.contact("select count(Username) from UserTable where User='",Txt_Name.Text.Trim(),", Password='",Txt_Password.Text.Trim(),"'"));
       Cmd.Connection=con;
       con.open();
       Int result=Cmd.ExecuteScalar();
       con.close(); 
       com.close();
       if(result==1)
         {
       Mainform main=Mainform();//登录成功。
       main.show();
       this.Hide();
         }
       else
    {  
        Message.Show("用户名密码错误!")
    }
    }