DataGridView控件的使用 1207
1.
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/022b0506aaa7ec6eaf2bcd6efab713a1.png#pic_center)
2.
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/3763fb8adf5ca6664fabad2e775eeb6e.png#pic_center)
3.
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/b4fdf8bcfa00d4a7340b0a3558f3a2eb.png#pic_center)
代码块
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace _1207_2_
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void Form1_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
string connStr = "Data Source=.;Initial Catalog=SangGuo;Integrated Security=True";
SqlConnection conn = new SqlConnection(connStr);
string sql = "select * from Table_1";
SqlDataAdapter adapter = new SqlDataAdapter(sql, conn);
adapter.Fill(ds, "SangGuo");
dataGridView1.AutoGenerateColumns = false;
dataGridView1.DataSource = ds.Tables["SangGuo"];
}
}
}