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数据库中的学生表,请改一下代码

C#VS2010访问SQL数据库
- 写回答
- 好问题 0 提建议
- 关注问题
- 邀请回答
-
7条回答 默认 最新
- threenewbee 2015-05-29 05:43关注
Sql和字段
要替换成你实际的变量。
给你代码不是照抄就行的,得看懂。本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报