Showing posts with label attribute. Show all posts
Showing posts with label attribute. Show all posts

Monday, March 19, 2012

ODBC command

hi,

I have a search function.

I was able to display attributes of a record in one table, but

I also need to get one attribute from another table.

My question is how can I implement inner join in this kind of query in odbc command?

this is a part of my code:

1'||||| Create Command Object2Dim odbcCommand_searchAs OdbcCommand =New OdbcCommand("Select TM0001.syain_id, TM0001.syain_name, TM0001.syain_pass, TM0001.empl_date, TM0001.birth_date, TM0011.office_name from TM0001,TM0011 where TM0001.syain_id = ? or TM0001.syain_name = ? and TM0011.office_id = TM0001.office_id ", MyConn)34'||||| Parameters and set values.5 odbcCommand_search.Parameters.Add("@.P1", OdbcType.Char).Value = TextBox_id_name.Text'emp_id.ToString6 odbcCommand_search.Parameters.Add("@.P1", OdbcType.Char).Value = TextBox_id_name.Text'emp_name.ToString789Dim objReaderAs Odbc.OdbcDataReader10 objReader = odbcCommand_search.ExecuteReader()11While objReader.Read()1213 TextBox_id.Text = objReader("syain_id")14 TextBox_name.Text = objReader("syain_name")15 TextBox_pswd.Text = objReader("syain_pass")16 DropDownList_office.Text = objReader("office_name")17 hire_date = objReader("empl_date")181920End While2122 objReader.Close()2324


All values can be displayed except for the "office_name" which is from another Table "TM0011".

hope you can help me with this.

thanks

sheila

You want something like

...from TM0001INNER JOIN TM0011ON TM0011.office_id = TM0001.office_id where TM0001.syain_id = ? or TM0001.syain_name = ?

That is the gist. Just make sure you are joining the matching fields that you are looking for.

|||

You can also try this:

Select TM0001.syain_id, TM0001.syain_name, TM0001.syain_pass, TM0001.empl_date, TM0001.birth_date, (SELECT TM0011.office_name FROM TM0011 WHERE TM0011.office_id = TM0001.office_id) FROM TM0001 WHERE TM0001.syain_id = ? OR TM0001.syain_name = ?