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.
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 ,
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 ,
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
Hi I'm having a problem implementing a mini shopping cart drop down in the header to show the user all the products they have in their shopping cart. It seems the only solution for this is Ajax, and I've looked all over and can't find anything that I could possibly ...
Hello All ...
Iam Getting An Error With try to excecute the stored procedure .
I have Have Sql database , the stored procedure like so :
USE [MPRS] GO /****** Object: StoredProcedure [dbo].[Search_Licenses_By_Number] Script Date: 26-Nov-16 8:06:52 AM ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO ALTER PROCEDURE ...
Help! I want to create a java program that finds the highest even integer among the values entered by the user. Stop asking values when a value less than 1 have been entered. If no even integer is entered, display "No Even Integer"
Here is the sample output that I ...