c#.net登陆问题

来源:百度知道 编辑:UC知道 时间:2024/06/03 19:42:42
string strQSL = "select * from Administrator where uid = '" + textBox1.Text + "' and upwd = '" + textBox2.Text + "'";
SqlConnection sqlcon = new SqlConnection();
sqlcon.ConnectionString = "server=192.168.1.106;uid=sa;pwd=123;database=offce";
try
{
sqlcon.Open();
//this.Visible = false;
//MessageBox.Show("连接成功");
SqlDataAdapter sqlda = new SqlDataAdapter(strQSL, sqlcon);
DataSet ds = new DataSet();
sqlda.Fill(ds, "Administrator");
SqlCmd = new SqlCommand(strQSL, sqlcon);
SqlCmd.BeginExecuteNonQuery();
int look = Convert.ToInt32(SqlCmd.ExecuteScalar());
if (look != 0)
{
this.Visible = false;

sqlcon.ConnectionString = "server=192.168.1.106;uid=sa;pwd=123;database=offce";
这个根据自己的要求修改一下。

string strQSL = "select * from Administrator where uid = '" + textBox1.Text + "' and upwd = '" + textBox2.Text + "'";
修改成:
string strQSL = "select * from Administrator where uid = '" + textBox1.Text.Tostring().Trim() + "' and upwd = '" + textBox2.Text.Tostring().Trim() + "'";
试试

SqlDataAdapter sqlda = new SqlDataAdapter(strQSL, sqlcon);
DataSet ds = new DataSet();
sqlda.Fill(ds, "Administrator");

throw new Exception("能过来吗?");

这2个只能写一个要是2个都写就有异常啦!一定要我这样写 你也可以添加引用from控件然后messagebox.show("问题");也可以打印至控制台!

SqlCmd = new SqlCommand(strQSL, sqlcon);
throw new Exception("过不来吧?哈哈");
SqlCmd.BeginExecuteNonQuery(