0

我收到一个错误,显示在“20”附近的预期条件的上下文中指定的非布尔类型的表达式。20 是查询字符串中的 SelectedPort 值我认为这个查询有问题。

string tablename = cboNetGuid.SelectedItem.ToString();

SqlConnection sqlConnectionCmdString = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Rick\Documents\Visual Studio 2010\Projects\Server\database\ClientRegit.mdf;Integrated Security=True;User Instance=True");

//Properly Defines the string for naming the table according to the systems naming scheme
string Command = "SELECT Client_Groups, Company, Occupation, ClientID FROM [" + tablename + "] WHERE Port = [" + SelectedPort + "]";

SqlCommand sqlCommand = new SqlCommand(Command, sqlConnectionCmdString);

// will be retrieved - reading methods
// sqlComgroup.Parameters["@Network"].Value = cboNetGuid.SelectedItem.ToString();

sqlConnectionCmdString.Open(); // open database connection

// create database reader to read information from database
SqlDataReader objReader = sqlCommand.ExecuteReader();

// retrieve information from database
while (objReader.Read())
{

  cboClientGroup.Items.Add(Convert.ToString(objReader["Client_Groups"]));

  cboOccupation.Items.Add(Convert.ToString(objReader["Occupation"]));

  cboCompany.Items.Add(Convert.ToString(objReader["Company"]));

  cboClientID.Items.Add(Convert.ToString(objReader["ClientID"]));
}

objReader.Close();
sqlConnectionCmdString.Close();
4

1 回答 1

3

您没有与SelectedPortSQL 中的任何内容进行比较。SQL 服务器需要一个类似的条件:

WHERE SelectedPort = Something
于 2013-07-24T22:30:44.177 回答