private void button1_Click(object sender, EventArgs e)
{
string ConnectionString = "Server=(local);Integrated Security=SSPI;Database=student";
SqlConnection myconn = new SqlConnection(ConnectionString);
myconn.Open();
MessageBox.Show("連接成功!");
SqlConnection conn = new SqlConnection(ConnectionString);
SqlCommand cmd = new SqlCommand(Sql, conn);
SqlDataReader dr = cmd.ExecuteReader();
while (dr.Read())
{
Console.WriteLine(dr[字段].ToString());
}
}
訪問SQL Server2008 student數據庫中的學生表,請改一下代碼
Sql和字段
要替換成你實際的變量。
給你代碼不是照抄就行的,得看懂。