|
- SqlConnection con = new SqlConnection("server=192.168.15.40;uid=sa;pwd=123456;database=coldSMS");
- try
- {
- con.Open(); //出现异常无法连接数据库
- SqlCommand com = con.CreateCommand();
- com.CommandType = CommandType.StoredProcedure;
- com.CommandText = "logg";
- com.Parameters.Add(new SqlParameter("@a", SqlDbType.Int, 4));
- com.Parameters["@a"].Value = logname;
- com.Parameters.Add(new SqlParameter("@b", SqlDbType.Int, 4));
- com.Parameters["@b"].Value = logpwd;
- com.Parameters.Add(new SqlParameter("@Return", SqlDbType.Int, 4));
- com.Parameters["@Return"].Direction = ParameterDirection.ReturnValue;
- com.ExecuteNonQuery();
- int i = Convert.ToInt32(com.Parameters["@Return"].Direction);
- if (i == 0)
- {
- MessageBox.Show("用户名或密码错误");
- this.txtZh.Text = "";
- this.txtMm.Text = "";
- this.txtZh.Focus();
- }
- else if (i == 1)
- {
- frmGnxzq objGnxzq = new frmGnxzq();
- this.Hide();
- objGnxzq.Show();
- }
- }
- catch (SqlException ex)
- {
- MessageBox.Show(ex.Message);
- }
- finally
- {
- //closesqlconnection();
- con.Close();
- con.Dispose();
- }
- }
复制代码 |
|