C#的DataGridView使用问题

来源:百度知道 编辑:UC知道 时间:2024/05/15 20:13:24
Form里创建了一个DataGridView控件,有个sql表 ,表名 hospital
想要在DataGridView里面显示hospital的内容,这个改怎么操作?我用的是.net 2005

就是直接设置DataGirdView数据源属性就行了,直接链接到hospital表就行了。不需要手动设置了。

我发个你整个程序吧,所有操作都有,很超值的。呵呵
在消息里给我你的邮箱。
--------------------------------------------------------
编辑 删除 等操作还是要手动的,还有
用objectdatasource要更好一些,使你的程序
更加清晰,符合起码的三层架构

void Page_Load(Object sender, EventArgs e)
{

if(!IsPostBack)
{

// Declare the query string.
String queryString =
"Select * FROM hospital";

// Run the query and bind the resulting DataSet
// to the GridView control.
DataSet ds = GetData(queryString);
if (ds.Tables.Count > 0)
{
AuthorsGridView.DataSource = ds;
AuthorsGridView.DataBind();
}
else
{
Message.Text = "Unable to connect to the database.";
}

}

}