I am trying to query my SQL Server database to populate a dataGridView. The user clicks on an item in a comboBox to select a 'program' to view. The where statement in the quers used the Text property from the comboBox. The code is:
SELECT CAMPAIGN_ID, CREDIT_GRADE_PRE, SUB_GRADE, APR, ANNUAL_FEE, CREDIT_LINE, SEGMENT, MAIL_CELL, MAILED, RESPONDED, APPROVED,
APPROVED_FICO, APPROVED_RISK
FROM [PROD_Mail Response]
WHERE (CAMPAIGN_ID = cboxMailRespSelProgram.Text)
The SQL query apparently does not find the comboBox.Text string and gives the following error message.
The multi-part identifier "cboxMailRespSelProgram.Text" could not be bound. I have already tried adding '.toString()' to the cboxMail... part without success. Suggestions?

Recommended Answers

All 9 Replies

post your entire code page for discussion

If you bind data source to ComboBox well,

CAMPAIGN_ID = int.Parse(cboxMailRespSelProgram.SelectedValue.ToString());

CAMPAIGN_ID = int.Parse(cboxMailRespSelProgram.SelectedValue.ToString());
Did Not Work! Thank you anyway.

So, follow Serkan and post the whole code here.

You need to escape your query and pass the text value of the combo box, not the literal name. You should also use parameterized queries but that is another discussion.
I'm assuming since you gave a multi-part exception that this is being raised by the SQL server and not the compiler:

Msg 4104, Level 16, State 1, Line 1
The multi-part identifier "combobox.text" could not be bound.

Try something like:

string query = "SELECT CAMPAIGN_ID, CREDIT_GRADE_PRE, SUB_GRADE, APR, ANNUAL_FEE, CREDIT_LINE, SEGMENT, MAIL_CELL, MAILED, RESPONDED, APPROVED, " + Environment.NewLine +
                     "APPROVED_FICO, APPROVED_RISK " + Environment.NewLine + 
                     "FROM [PROD_Mail Response] " + Environment.NewLine + 
                     string.Format("WHERE (CAMPAIGN_ID = {0})", cboxMailRespSelProgram.Text);

So, follow Serkan and post the whole code here.

see you come to my point once more :)
Respect my Authority!!! :)

see you come to my point once more :)
Respect my Authority!!! :)

Did I write too much code again? :(

no it was a response to Ramy, anyway i gotta go to get some ice cream from publix immediatly as it closes at 10 pm here in USA :)
probably hagendas or publix own icecream brand, i got 30 minutes left with UTC time.
i need to get my ass up!!

I am trying to query my SQL Server database to populate a dataGridView. The user clicks on an item in a comboBox to select a 'program' to view. The where statement in the quers used the Text property from the comboBox. The code is:
SELECT CAMPAIGN_ID, CREDIT_GRADE_PRE, SUB_GRADE, APR, ANNUAL_FEE, CREDIT_LINE, SEGMENT, MAIL_CELL, MAILED, RESPONDED, APPROVED,
APPROVED_FICO, APPROVED_RISK
FROM [PROD_Mail Response]
WHERE (CAMPAIGN_ID = cboxMailRespSelProgram.Text)
The SQL query apparently does not find the comboBox.Text string and gives the following error message.
The multi-part identifier "cboxMailRespSelProgram.Text" could not be bound. I have already tried adding '.toString()' to the cboxMail... part without success. Suggestions?

Hi first get dataset from database
then assign value to datagrid as codebehiend
gvDetails.datasource = datasetName;
gvDetails.DataBind();

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.