hi everyone , can someone help me by this
i have a DB table and a form the following fields , combobox and textboxes, what i need is how to write a query to retrieve data from the table when the user select some record from combobox

thnx before and help me plz ,

The standard select statement has the form of

SELECT col_name1, col_name2, etc FROM table_name WHERE some_col = some_value;

So you will want to store the selected option from the combobox and then add it to the SQL statement. You haven't given us much to go on, do you know how to create a database connection with a connection string, put your SQL statement into a command object and execute the command? If not, type ".net database tutorial" into google and follow along.
Of course, if you have specific problems and questions post them back here and we'll help out.

commented: I will give credit where credit is due. +5

TY Hericles, but not that what i meant , what i need is how to make the data that store in sql appear in textboxes depending on some field that is it ,
example :
i have project tendering no in table and all information about it , and in form i have combobox bounded with this field , when the user select from combobox i need all save data about this project appear in textboxes in same form , help me if u can ...

please someone help me , i cant solve alone..

You can use what hericles has posted and append the following:

   Dim con As New SqlConnection("Connection string here")
    con.Open()

    Dim sqls As String = "SELECT col_name1, col_name2 FROM table_name WHERE some_col = some_value;"

    Dim cmd As New SqlCommand(sqls, con)

    Dim da As New SqlDataAdapter(cmd)

    Dim ds As DataSet

    da.Fill(ds, "Values I Need")

    Dim dt As New DataTable

    dt = ds.Tables("Values I Need")

    If dt.Rows.Count > 0 Then
        For i = 0 To dt.Rows.Count - 1
            TextBox1.Text = dt.Rows(i).Item(0)  'col_name2'
            TextBox1.Text = dt.Rows(i).Item(1)  'col_name2'
        Next
    End If

well if you have a form having diff controls , like datetime picker , picture box , textboxes and you want to populate them by using combo box. you have to bind all your controls with your datasource , like this .

dim con as new sqlconnection("you connection string")
con.open
dim da as new sqldataadapter("select * from table1 where name ='" &      combobox1.selectedvalue & "'",con)
dim dt as new datatable
da.fill(dt)
con.close
'take a binding source from tool box.
bindingsource1.datasource = dt 
'here you can bind your controls like this.
datetimepicker.databinding.add("text",bindingsource1,"_ur_datefieldname",false)
Picturebox1.databinding.add("image",bindingsource1,"_ur_Pixfieldname",true)
radiobutton.databinding.add("checked",bindingsource1,"_ur_fieldname",true)
checkbox.databinding.add("checked",bindingsource1,"_ur_fieldname",true)
combobox.databinding.add("text",bindingsource1,"_ur_fieldname",false)
textbox1.databinding.add("text",bindingsource1,"_ur_fieldname",false)

hope this code will help you ,

Best Regards

Something like this might help u...

'Open_DB_Connection
Try
     Dim myCommand As SqlCommand
     myCommand = New SqlCommand("SELECT  * FROM Tablename where ID='" & combobox1.Text & "'", Connection)
     Dim reader As SqlDataReader = myCommand.ExecuteReader
     While reader.Read
           txtID.Text = reader("ID")
           txtName.Text = reader("Name")
           txtCost.Text = reader("Cost")
     End While
     reader.Close()
Catch ex As Exception
     MsgBox("Error Connecting to Database: " & ex.Message)
End Try
'Close_DB_Connection
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.