sql数据源连接

扫码查看
本文介绍了sql数据源连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我正处于学习阶段.
我想学习与数据源工具的连接性.
只需使用2个文本框和2个标签名称作为用户名和密码.
以按钮名称登录.
现在在sql中创建一个数据库,并插入一个用户名和密码.
然后再次进入设计部分并添加数据源控件.然后将其与sql连接.
之后,我希望对登录按钮进行编码,就像用户输入正确的名称和密码一样,那么它应该重定向到另一个页面,否则应该显示说明用户名和密码无效的消息框.
请先生给这个编码......在C#中.
谢谢您,先生....

sir i am in just learning phase.
i want to learn connectivity with the data source tool.
just take 2 text box and 2 label name them as user name and password.
take a button name it login.
now create an database in sql.and insert one user name and password.
then again come design part and add data source control.then connect it with sql.
after that i want the coding for login button as if the user enters the correct name and password then it should redirect to another page or else it should message box stating invalid user name and password.
pls sir give this coding......in c#.
thank you sir....

推荐答案


private void button1_Click(object sender, EventArgs e)
       {
           string cmd="select *from Admin where ID='"+txtFilenO.Text+"' and Password='"+textBox1.Text+"' ";
          SqlConnection con=new SqlConnection();

           con.connectionString="Paste Connection String";
            con.Open();
SqlCommand cmd1 = new SqlCommand(cmd,con);

           SqlDataReader dr = cmd1.ExecuteReader();
           if (dr.Read())
           {
               AdminMenu n = new AdminMenu();
               n.lblsser.Text = dr[0].ToString();
               n.Show();
               this.Dispose();
               this.Close();
               cmd1.Connection.Close();

           }
           else
           {
               cmd1.Connection.Close();
               MessageBox.Show("ID/Password is not valid");
           }

       }



它是向导的连接,但是您应该学习每个关键字的含义,所以请保持从Google和MSDN的收益.



it is connection from wizard,But You should learn meaning of each keyword, So keep l;earning from Google and MSDN.


这篇关于sql数据源连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 10:21
查看更多