c#怎么书写连接sqlserver数据库的语句

2024-11-01 14:23:15
推荐回答(1个)
回答1:

private void button1_Click(object sender, EventArgs e)
{
string con, sql;
con = "Server=.;Database=Exercise;Trusted_Connection=SSPI";
sql = "select * from lianxi";
SqlConnection mycon = new SqlConnection(con);
mycon.Open();
SqlDataAdapter myda = new SqlDataAdapter(sql, con);
DataSet myds = new DataSet();
myda.Fill(myds, "lianxi");
dataGridView1.DataSource = myds.Tables["lianxi"];
}