0

An expression of non-boolean type specified in a context where a condition is expected, near '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