hi i'm a beguiner in visual basic

i have a datagrid view filled with a dataset table thats combined by 2 tables 1-persons 2- actions

i want to select a row in the grid view and get the person table where personid is selected in datagridview

i assume that it is pretty simple but i can't get it
thanks

i cant get your point , i think you want to select all records from persons table of selected person id in grid , if i am wrong then please correct me , well for simple select case you can do like this

dim myCmd as string 
myCmd = "select * from persons where personID=" val(datagridview1.item("Personid",datagridview1.currentrow.index).value.tostring)'you can use index of your column in place of "personid".

this will select all the records from the table persons of selected personid

Regards

thanks that what i wanted to know

is there a way that i can do this by seting the detailed form's bindingsource somehow?

becuase the personid column that i refer to is not in the datagridview

i got this error "Column named personid cannot be found.
Parameter name: columnName"

in above code we use selected value from the cell of the grid to get all the records of that selected value ,now what is your question please rephrase it .so that i can help you in better and effective way

Regards

my gridview is combined by 2 tables and the id of both isn't on the gridview i want to get the selected row of the gridview to select the row on table1
so your solution didn't work because the id is not on the gridview
i solved it by placing the id on the gridview and seting the visible property to false

any other ideas how to do this?

i dont know which fields you are taking in grid , lets consider if there is a table name student , having ids , stuid , stuname , stufathername ,stuphonno, now you are showing stuname , stufathername,stuphone in grid and want to do same as you mentioned above then you can write this code for selection.

dim myCmd as string 
myCmd = "select * from persons where stuname='"datagridview1.item("StuName",datagridview1.currentrow.index).value.tostring &"' and stufathername= '"& datagridview1.item("stufathername",datagridview1.currentrow.index).value.tostring&"' and stuphoneno='"&val(datagridview1.item("stuphone",datagridview1.currentrow.index).value.tostring &"'"

Regards

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.