自知代码写的很不严谨,
一直没有想到这个问题上来,是因为这个程式写出来暂时只给自己部门人用的,希望各位老师指点下,我要怎么改才好?
下面是代码
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.textBox1.Text.Trim()))
{
try
{
string a = this.textBox1.Text.ToUpper().Trim();
string b = this.textBox2.Text.Trim();
string sql = @"SELECT * from wo_no where workno ='" + a + "' and password='"+b+"'";//查询数据库里的账号与密码
SqlConnection conn = new SqlConnection("server=服务器IP;database=meshr;User ID=sa;Password=数据库密码;");//打开sql server数据库
SqlCommand cmd=new SqlCommand(sql,conn);
SqlDataAdapter data =new SqlDataAdapter();
data.SelectCommand = cmd;
DataSet ds = new DataSet();
data.Fill(ds, "cs");
if (ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("请输入正确账号或密码!");
textBox1.Text = "";
textBox2.Text = "";
}
else
{
username = textBox1.Text;
Form1 f1 = new Form1();
f1.Show();
//this.Hide();//登陆窗口开启后瘾藏
}
}
catch (SqlException)
{
return ;
}
}
else
{
MessageBox.Show("请输入账号!"); //如果账号栏为空,则show出提示.
return ;
}
}
一直没有想到这个问题上来,是因为这个程式写出来暂时只给自己部门人用的,希望各位老师指点下,我要怎么改才好?
下面是代码
private void button1_Click(object sender, EventArgs e)
{
if (!string.IsNullOrEmpty(this.textBox1.Text.Trim()))
{
try
{
string a = this.textBox1.Text.ToUpper().Trim();
string b = this.textBox2.Text.Trim();
string sql = @"SELECT * from wo_no where workno ='" + a + "' and password='"+b+"'";//查询数据库里的账号与密码
SqlConnection conn = new SqlConnection("server=服务器IP;database=meshr;User ID=sa;Password=数据库密码;");//打开sql server数据库
SqlCommand cmd=new SqlCommand(sql,conn);
SqlDataAdapter data =new SqlDataAdapter();
data.SelectCommand = cmd;
DataSet ds = new DataSet();
data.Fill(ds, "cs");
if (ds.Tables[0].Rows.Count == 0)
{
MessageBox.Show("请输入正确账号或密码!");
textBox1.Text = "";
textBox2.Text = "";
}
else
{
username = textBox1.Text;
Form1 f1 = new Form1();
f1.Show();
//this.Hide();//登陆窗口开启后瘾藏
}
}
catch (SqlException)
{
return ;
}
}
else
{
MessageBox.Show("请输入账号!"); //如果账号栏为空,则show出提示.
return ;
}
}





