private void button1_Click(object sender, EventArgs e)
{
DataSet ds = new DataSet();
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = "server=localhost;uid=sa;pwd=123456;database=table1";
conn.Open();
using (SqlCommand command = conn.CreateCommand())
{
command.CommandText = "select * from gongneng";
SqlDataAdapter da = new SqlDataAdapter(command);
try
{
da.Fill(ds);
}
catch
{ }
}
}
DataTable dt=new DataTable ();
dt = ds.Tables[0].Copy();
this.dataGridView1.DataSource = dt; //绑定到datagridview中显示
}
作者:qxlwuyuhui0801
来源:CSDN
原文:https://blog.csdn.net/qxlwuyuhui0801/article/details/8023545
版权声明:本文为博主原创文章,转载请附上博文链接!