我正在尝试dgvEmployees
从我的表中将记录检索到我的数据网格视图中tblEmployees
。我不确定出了什么问题,也许是因为语法?但该代码在使用 MS Visual C# 2010 Express(仅限 WinForms)之前已经运行。我目前正在使用 MS Visual Studio (ASP.NET - C#) 创建一个带有 winforms 的网页。这是我的代码:
SqlConnection sConn;
SqlDataAdapter daEmp;
DataSet dsEmp;
const string sStr = "Server = MYSERVER\\SQLEXPRESS; Database = EMPLOYEES; Integrated Security = SSPI";
protected void Page_Load(object sender, EventArgs e)
{
sConn = new SqlConnection(sStr);
daEmp = new SqlDataAdapter("Select * from tblEmployees", sConn);
dsEmp = new DataSet();
daEmp.Fill(dsEmp, "tblEmployees");
dsEmp.Tables["tblEmployees"].PrimaryKey = new DataColumn[] { dsEmp.Tables["tblEmployees"].Columns["EmployeeID"] };
dgvEmployees.DataSource = dsEmp.Tables["tblEmployees"];
}
这是此行的错误消息(daEmp.Fill(dsEmp, "tblEmployees");
Invalid object name 'tblEmployees'
请帮忙。谢谢!