日期:2014-05-17 浏览次数:20826 次
private void button1_Click(object sender, EventArgs e)
{
//连接语句
string connTeststr = "Data Source=.;Initial Catalog=TEST;Integrated Security=True";
string connStustr = "Data Source=.;Initial Catalog=student;Integrated Security=True";
//SqlConnection建立连接
SqlConnection connTest = new SqlConnection(connTeststr);
SqlConnection connStu = new SqlConnection(connStustr);
//打开连接
connTest.Open();
connStu.Open();
//连接测试
if (connTest.State == ConnectionState.Open)
{ label1.Text = "TEST连接成功"; }
else
{ label1.Text = "连接失败"; }
if (connStu.State == ConnectionState.Open)
{ label2.Text = "STU连接成功"; }
else
{ label2.Text = "连接失败"; }
//上面连接 已经成功
//下面该DATASET 测试
SqlCommand Cmd = new SqlCommand("select 学号 from XSB", connStu);
SqlDataReader reader = Cmd.ExecuteReader();
string bkstr = reader.GetString(0);
textBox1.Text = bkstr;
reader.Close();
}