任何有关这方面的帮助将不胜感激.每当我运行我的程序时,我得到一个NullReferenceException未被用户代码处理.
因此,当我启动程序时,我会看到一个表单,我应该从名单列表中进行选择,并能够更新详细信息或删除它们,但下拉列表中没有任何内容.
我得到空引用:
comm.Parameters["@EmployeeID"].Value =
employeesList.SelectedItem.Value;
Run Code Online (Sandbox Code Playgroud)
这是CS文件中的选择按钮:
protected void selectButton_Click(object sender, EventArgs e)
{
// Declare objects
SqlConnection conn;
SqlCommand comm;
SqlDataReader reader;
// Read the connection string from Web.config
string connectionString =
ConfigurationManager.ConnectionStrings[
"HelpDesk"].ConnectionString;
// Initialize connection
conn = new SqlConnection(connectionString);
// Create command
comm = new SqlCommand(
"SELECT FirstName, LastName, Username, Address, City, County, Post Code, " +
"HomePhone, Extension, MobilePhone FROM Employees " +
"WHERE EmployeeID = @EmployeeID", conn);
// Add command parameters
comm.Parameters.Add("@EmployeeID", System.Data.SqlDbType.Int);
comm.Parameters["@EmployeeID"].Value = …Run Code Online (Sandbox Code Playgroud) c# sql asp.net nullreferenceexception visual-web-developer-2010