how to made combobox drop down change its list in correspondence to another combobox?

I am currently working on a small project for a business society in visual studio 2015 and SQL server. I have two comboboxes "AccountCode" and "AccountNo". I want to made "AccountNo" combobox to change its value in correspondence with the selection of a text from "AccountCode" drop down. But i get following error:

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: The multi-part identifier "System.Data.DataRowView" could not be bound.

private void cmBxAccountCode_DataEntry_SelectedIndexChanged(object sender, EventArgs e)
    {
        cmBxAccountNo_DataEntry.ResetText();
        cmBxAccountNo_DataEntry.Refresh();
        DataSet ds = new DataSet();
        da.SelectCommand = new SqlCommand("SELECT ID,ACCOUNTNO FROM  AccountHolder WHERE ACCOUNTCODE =" + cmBxAccountCode_DataEntry.Text, SQLConnection.con);
        da.Fill(ds);
        cmBxAccountNo_DataEntry.DataSource = ds.Tables[0];
        cmBxAccountNo_DataEntry.DisplayMember = "ACCOUNTNO";
        cmBxAccountNo_DataEntry.ValueMember = "ID";
    }

Answers


Your query should be like this:

SELECT ID,ACCOUNTNO FROM  AccountHolder WHERE ACCOUNTCODE ='" + cmBxAccountCode_DataEntry.Text  + "'"

But i strongly recommend you to use Parameterized queries to avoid injection; And also take selected value instead for Text( but it is according to the value in the database). The parameterized query will be like this :

// Code here
SqlCommand selectCommand=  new SqlCommand("SELECT ID,ACCOUNTNO FROM  AccountHolder WHERE ACCOUNTCODE =@accountCode", SQLConnection.con);
selectCommand.Parameters.Add("@accountCode", SqlDbType.VarChar).Value = cmBxAccountCode_DataEntry.Text;
// execute here

Need Your Help

Not sure if my SQL JOIN is returning the correct set for my assignment

sql database oracle

I'm learning about JOINS and need help with the following question: