i am filling gridview with with tblJobADv

columns: userid, advid (f.k), remarks

now i actually want to select advTitle from tblJobAdv from which i already imported foreignkey advid , and want to appear it next to advid column in gridview, so how

i know the query ,

SELECT advTitle from tblJobAdv where advid= @advid

but how to put a column in table ? advTitle

help please

Hi
I'm not 100% sure what your asking, my first guess is that you want to put the results of a query that queries two tables into your gridview? i.e. Get advTitle from another table into your grid?

You need to join the two tables in your select query then use a dataadaptor to fill a dataset with the query result. You will then be able to retieve the Result set as a single datatable:

'I'll assume your using a SQL database
dim DA as sqldataadapter
dim DS as new dataset
dim DT as Datatable
dim cmd as sqlcommand
dim conn as new sqlconnection ("Your connection String")
dim sSQL as string
dim advidid as integer  'You'll populate this with the correctID 

'Now formulate your SQL query I don't see what your first table was called - I'll use tblJobApp
sSQL = "SELECT tblJobApp.userID, tblJobApp.advid, tblJobAdv.Title, tblJobApp.Remarks" & _ 
"FROM tblJobApp INNER JOIN tblJobAdv ON (tblJobApp.advidid = tblJobAdv.advidid) " & _ 
"WHERE (tblJobAdv.advidid =" &avidid &")"

If conn.state <> connectionstate.Open then
    conn.open
end if

cmd = new sqlcommand
cmd.CommandType = Commandtype.text
cmd.CommandText = sSQL
cmd.Connection = conn

DA = New SqlDataAdapter
DA.SelectCommand = cmd
DA.Fill(DS)
DT = DS.Tables(0)

MyGrid.Datasource = DT
MyGrid.Columns(1).Visible = false 'will hide the avidid form the users

If you need help with joking SQL tabes, provide us with the table names ad their fields.

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.