主题:关于DataGridView在WinForm的基础应用问题,请大家帮帮我吧!
刚学习DataGridView,想编一个win程序,功能很简单,就是一个DataGridView控件用于显示数据库中一个表的所有内容,但是我写的这个程序虽然语法没有问题,但是确不能显示,请大家帮帮我,谢谢了!
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//1---建立连接
SqlConnection connection = new SqlConnection(@"Server=.;Integrated security=True;Database=SJ_SHIPPING_DB_NEW");
//2---创建Adapter
SqlDataAdapter Adapter = new SqlDataAdapter(@"SELECT * FROM dbo.DECLARE_I_INFO_REL",connection);
//3---建立一个数据集
DataSet ds = new DataSet();
//4---将Adapter的内容填充至数据集
Adapter.Fill(ds);
this.dataGridView1.DataSource = ds;
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace test
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
//1---建立连接
SqlConnection connection = new SqlConnection(@"Server=.;Integrated security=True;Database=SJ_SHIPPING_DB_NEW");
//2---创建Adapter
SqlDataAdapter Adapter = new SqlDataAdapter(@"SELECT * FROM dbo.DECLARE_I_INFO_REL",connection);
//3---建立一个数据集
DataSet ds = new DataSet();
//4---将Adapter的内容填充至数据集
Adapter.Fill(ds);
this.dataGridView1.DataSource = ds;
}
}
}