C#链接数据库直接在datagridview里面修改数据
我的连接数据库代码是:SqlConnection conn = new SqlConnection(@"Data Source=SAMSUNG-PC;Initial Catalog=jsflxt;Integrated Security=True");
try
{
conn.Open();
}
catch (Exception e)
{
}
return conn;
}
public void data()
{
SqlConnection conn = OpenCon();
SqlCommand cmd = new SqlCommand();
= "select * from jsxx";
cmd.Connection = conn;
SqlDataAdapter s = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
s.Fill(ds);
this.dataGridView1.DataSource = ds.Tables[0];
}
求写代码!