gridview 绑定数据库

来源:百度知道 编辑:UC知道 时间:2024/06/20 02:19:26
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Get_Data();

}
protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
{

}
private void Get_Data()
{ SqlConnection con=new SqlConnection("Server=.;database=logins;uid=zys;pwd=123;");
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * fron person", con);
DataSet ds = new DataSet();
sda.Fill(ds,"p");
this.GridView1.DataSource=ds.Tables["p"];
this.GridView1.DataBind();

}

}
为什么我用vs2005老是提示错误呢,请高手帮我解决,我哪里错了

con没有打开
con.open();

sql语句写错了

你把from 写成了 fron

数据连接没有打开
private void Get_Data()
{ SqlConnection con=new SqlConnection("Server=.;database=logins;uid=zys;pwd=123;");
con.open();
SqlDataAdapter sda=new SqlDataAdapter();
sda.SelectCommand=new SqlCommand("select * fron person", con);
DataSet ds = new DataSet();
sda.Fill(ds,"p");
this.GridView1.DataSource=ds.Tables["p"];
this.GridView1.DataBind();

}