关于绑定DataGrid的一个问题
想学数据库编程,控制台程序还行,可是一到控件的绑定就不行了,就是得不到想要的结果,请高人帮我看一下这个源码!using System;
using System.Data;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace DataGrid
{
public partial class Form1 : Form
{
// private System.Data.DataSet dataSet1;
private System.Windows.Forms.DataGrid dataGrid1=null;
//private System.Windows.Forms.Button button1;
private System.Data.SqlClient.SqlCommand sqlCommand1;
private SqlCommandBuilder cb;
private SqlDataAdapter da;
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
string ConStr = @"Data Source=(local);Integrated Security=SSPI;" + "Initial Catalog=NorthWind";
string SQL = "select * from Employees";
SqlConnection Conn = new SqlConnection(ConStr);
sqlCommand1 = new SqlCommand(SQL, Conn);
da = new SqlDataAdapter();
da.SelectCommand = sqlCommand1;
cb = new SqlCommandBuilder(da);
da.Fill(dataSet1, "Employees");
dataGrid1.SetDataBinding(dataSet1, "Employees");
}
private void button1_Click(object sender, EventArgs e)
{
da.Update(dataSet1, "Employees");
}
}
}
编译能通过,红色的三句是提示有错误我改的!我想在DataGrid中显示Employees表的内容,可就是显示不出来!请高人帮忙!谢谢!