I have two tables.
Table 1: supportstatus
clientid
company
status
Table 2: client
clientid
company
status
state
I am also using a table with 2 columns to seperate the grid view results. I am currently trying to make two queries that will return the clients with a disabled status in one table column and their corresponding states in the other. Any assistance with an explanation would be appreciate.
protected void queryClientCompanyName()
{
string MyConString = "Driver={MySQL ODBC 5.1 Driver};Server=**;Database=support;User=**; Password=**;Option=3;";
string queryString = "SELECT company FROM supportstatus WHERE status = 'disabled' Order By company";
OdbcConnection conn = new OdbcConnection(MyConString);
conn.Open();
OdbcCommand command = new OdbcCommand(queryString, conn);
OdbcDataReader reader = command.ExecuteReader();
populateGrid(reader, GridView1);
conn.Close();
RecordCountLabel.Text = GridView1.Rows.Count.ToString();
}
protected void queryClientCompanyState()
{
string MyConString = "Driver={MySQL ODBC 5.1 Driver};Server=**;Database=support;User=**; Password=**;Option=3;";
string queryString = "SELECT cl.state FROM clients cl, supportstatus su WHERE cl.clientid = su.clientid AND su.status='disabled' Order By cl.company";
OdbcConnection conn = new OdbcConnection(MyConString);
conn.Open();
OdbcCommand command = new OdbcCommand(queryString, conn);
OdbcDataReader reader = command.ExecuteReader();
populateGrid(reader, GridView2);
conn.Close();
}
You should only need the following query to replace both of yours:
You want one query that will return both values so you know that they are related. It is because of this that you want to join the tables together. I just did a quick google search and W3schools has basic join information, so does techrepublic These should help you with the basic concepts of querying a database.