怎样把数据库的表显示到datagridview中?
其实很简单。
我们只需要在窗体上拖放一个datagridview 然后双击窗体空白处,在代码文件的Form1_Load事件中添加括号里的代码 private void Form1_Load(object sender, EventArgs e) { string strsql="select * from stop where stop_id>5";//查询语句。SqlConnection conn = new SqlConnection("server=.;uid=sa;pwd=sa;database=BUSTWO"); SqlCommand cmd = new SqlCommand(strsql, conn); SqlDataAdapter da = new SqlDataAdapter(cmd); DataSet ds = new DataSet(); da.Fill(ds); dataGridView1.DataSource = ds.Tables[0]; } 即可,Copyright © 广州京杭网络科技有限公司 2005-2025 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有