retrieving the data by passing 2 parameters

srivalli

Well-known member
Joined
May 4, 2005
Messages
189
Programming Experience
Beginner
by passing one parameter as id, we can get that corresponding fields. but how to pass two parameters as i/p and get that corresponding details.
thks
 
You'll have to be more specific about what you are trying to do. Where are you passing parameters too? What is the datasource? etc
 
passing 2 parameters as input and retrieving data

i pass id as input ,and i ll retrieve that id corresponding details in different textboxes.
now my query is i want to pass id as well as date in 2 different textboxes and i want to retrieve that id and date corresponding details.hope now my query is clear.thanks
levyuk said:
You'll have to be more specific about what you are trying to do. Where are you passing parameters too? What is the datasource? etc
 
If you are currently using SQL similar to:

SELECT * FROM Table WHERE id = <idvalue>

then you would now use something like:

SELECT * FROM Table WHERE id = <idvalue> AND date = #<datevalue>#

Dates may get passed to different databases in different ways.
 
passing 2 parameters as input and retrieving data

i am trying to take idvalue in one textbox and date in another textbox.and i am not mentioning the date or id value directly in the query .i dont know whether it is write or wrong.by the way the line u coded

SELECT * FROM Table WHERE id = <idvalue> AND date = #<datevalue>#
is showing error at AND .
any new suggestions
thks
jmcilhinney said:
If you are currently using SQL similar to:

SELECT * FROM Table WHERE id = <idvalue>

then you would now use something like:

SELECT * FROM Table WHERE id = <idvalue> AND date = #<datevalue>#

Dates may get passed to different databases in different ways.
 
I think I now understand. You should create your select command using parameters. You can then set the parameter values from the TextBoxes. I would, however, recommend using a DateTimePicker for the date rather than a TextBox. That way there are no issues with format.
VB.NET:
		Dim connection As New OleDb.OleDbConnection
		Dim adapter As New OleDb.OleDbDataAdapter("SELECT * FROM Table1 WHERE idfield = @id AND datefield = @date", connection)
		Dim table As New DataTable

		adapter.SelectCommand.Parameters.Add("@id", OleDb.OleDbType.Integer)
		adapter.SelectCommand.Parameters.Add("@date", OleDb.OleDbType.DBDate)

		adapter.SelectCommand.Parameters("@id").Value = Me.TextBox1.Text
		adapter.SelectCommand.Parameters("@date").Value = Me.DateTimePicker1.Value.Date

		adapter.Fill(table)
I have not specifically tested this code but it should work. You will obviously need to substitute your own table, field and control names. Note that if the id field is your primary key then adding the date field will not have any effect except to return no rows if the dates don't match.
 
Back
Top