以下是我想将vs建立的表的数据读出来,显示在DataGridView1上,但是总出现错误。谁能帮忙解决下啊,感激不尽???
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication11
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
private void tongxunlu_Load(object sender, EventArgs e)
{
string connstr=@"Data Source=.\sqlexpress;Initial=Datebase1;Integrated Security=True";
srting sql="select * from tongxunlu";
Sqlconnection conn=new Sqlconnection(connstr);
SqlDataAdapter adapter=new SqlDataAdapter(sql,conn);
DataSet ds=new DataSet();
adapter.Fill(ds);
ds.Tables[0].Columns[0].ColumnName="姓名";
ds.Tables[0].Columns[1].ColumnName="地址";
ds.Tables[0].Columns[2].ColumnName="邮编";
ds.Tables[0].Columns[3].ColumnName="电话1";
ds.Tables[0].Columns[4].ColumnName="电话2";
ds.Tables[0].Columns[5].ColumnName="电子邮件";
DataGridView1.DataSouce=ds.Tables[0].DefaultView;
name.DataBings.Add("Text",ds.Tables[0],"姓名");
address.DataBings.Add("Text",ds.Tables[0],"地址");
youbian.DataBings.Add("Text",ds.Tables[0],"邮编");
tel1.DataBings.Add("Text",ds.Tables[0],"电话1");
tel2.DataBings.Add("Text",ds.Tables[0],"电话2");
email.DataBings.Add("Text",ds.Tables[0],"电子邮件");
}
}
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication11
{
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
}
private void Form2_Load(object sender, EventArgs e)
{
private void tongxunlu_Load(object sender, EventArgs e)
{
string connstr=@"Data Source=.\sqlexpress;Initial=Datebase1;Integrated Security=True";
srting sql="select * from tongxunlu";
Sqlconnection conn=new Sqlconnection(connstr);
SqlDataAdapter adapter=new SqlDataAdapter(sql,conn);
DataSet ds=new DataSet();
adapter.Fill(ds);
ds.Tables[0].Columns[0].ColumnName="姓名";
ds.Tables[0].Columns[1].ColumnName="地址";
ds.Tables[0].Columns[2].ColumnName="邮编";
ds.Tables[0].Columns[3].ColumnName="电话1";
ds.Tables[0].Columns[4].ColumnName="电话2";
ds.Tables[0].Columns[5].ColumnName="电子邮件";
DataGridView1.DataSouce=ds.Tables[0].DefaultView;
name.DataBings.Add("Text",ds.Tables[0],"姓名");
address.DataBings.Add("Text",ds.Tables[0],"地址");
youbian.DataBings.Add("Text",ds.Tables[0],"邮编");
tel1.DataBings.Add("Text",ds.Tables[0],"电话1");
tel2.DataBings.Add("Text",ds.Tables[0],"电话2");
email.DataBings.Add("Text",ds.Tables[0],"电子邮件");
}
}
}
}