using System.Data.SqlClient; protected System.Web.UI.WebControls.DataGrid DataGrid1;
private void Page_Load(object sender, System.EventArgs e)
{
// 在此处放置用户代码以初始化页面 DataGrid1.DataSource = dg_data();
} public SqlDataReader dg_data()
{
string database = "data source = mydatasource;database = mydatabase;uid = myname;pwd = mycode";
string connection = "select * from table1"; SqlConnection conn = new SqlConnection(database); SqlCommand cmd = new SqlCommand(connection,conn); conn.Open(); SqlDataReader dr = cmd.ExecuteReader(CommandBehavior.CloseConnection); return dr;
}在以上的代码中,DataGrid1应该是读取表table1的数据的,但运行的时候没有任何数据。
问题何在??