Hi.
I have a database that has a table named "Main", this table has 4 elements "ID, Blue Number, Year, Description" .
What i need is how can i make a form that has only a search box to search using any given blue number, and once the blue number is entered into the text box the program will search the database for all other elemnts to that blue number.
Anyone can help plz

How to make a search box in an application
tviel
I forgot to mention the error I am getting.
This is where the debugger highlights:
MyReader = MyCommand.ExecuteReader
This is the error stated
OleDbException was unhandled
No value given for one or more required parameters.
ThanksBjorn EP Backlund
This is how i tried to do it :
1: Made a form with a button (Button1), a textbox (TexBox1) & a listbox (ListBox1).
2: Went to Data Sources tab and selected my database and then selected the table i want to use (Table1) and the dataset name is memsDataSet.
3: Inserted the following code into Button1 :
Do
Dim MyCommand As OleDb.OleDbCommand
Dim MyParam As OleDb.OleDbParameter
Dim MyConnection As OleDb.OleDbConnection
Dim MyReader As OleDb.OleDbDataReader
MyConnection.Open()
MyParam = Me.TextBox1.Text
MyCommand.Parameters.Add(MyParam)
MyCommand.CommandText = "Select [Blue] From Table1 Where [Blue] = "
MyReader = MyCommand.ExecuteReader
While MyReader.Read
Me.ListBox1.Items.Add(MyReader(0))
End While
MyConnection.Close()
Loop
4: The error i have is " Value of type 'String' cannot be converted to 'System.Data.OleDb.OleDbParameter' "
So, what's wrong
Donaghy
Thanks DMan1 for replying.
But, if you can can you explain more
My form has : textbox1, button1 & listbox1
My database has one a table called Table1 and 3 items ID, Blue & Name
Dataset name = memsDataSet.
How can i implement the code you gave me
Sorry i'm a novice
GDigrego
Anthony M
MyCommand
.Connection = MyConnectionRaihan Iqbal
fbiots
Here I am
...
A couple of problems...First get rid of the 'Do loop' and second...
Set your connection string:
Dim MyConnection As New OleDb.OleDbConnection("
Dim MyCommand As New OleDb.OleDbCommand
Dim MyParam As New OleDb.OleDbParameter
& Then
the parameter value is = to the text :
MyParam.Value = Me.TextBox1.TextJulian V
A1Programmer
http://msdn2.microsoft.com/en-us/vbasic/ms789075.aspx#data
Data Access Samples
The Data Access samples show how to use the classes in the System.Data and related namespaces. In addition, how to use the new features of SQL Server 2005. Samples include:
Download the Visual Basic version of the Data Access samples.
Learning ADO.NET:
DDressel
Zac Boyles
Hi, I have been trying to make a similar search happen, but I can't seem to get it to work. I am trying to make an addressbook for my wife. She wants to be able to do a search on a number of fields such as birthday month to get all the people she needs to send cards to etc. Or to find a phone number. I have written the code to clear all the textboxes and do a search on each to determine which field was enterwed to search for. This was then assigned to a variable. The column name is also assigned to a variable based on the previous one. Using these variables I can't seem to get the code written above to work. Any Ideas Here is my code for the search button. PS Brand new to all programming and trying to self teach > not going to fast haha
Dim
Search As String Dim Column As String Dim MyCommand As New OleDb.OleDbCommand Dim MyParam As New OleDb.OleDbParameter Dim MyConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source= C:\gistemp\VBDotNet\Addressbook.mdb") Dim MyReader As OleDb.OleDbDataReader
If FirstNameTextBox.Text <> "" ThenSearch = FirstNameTextBox.Text
Column =
"Firstname" ElseIf SurnameTextBox.Text <> "" ThenSearch = SurnameTextBox.Text
Column =
"Surname" ElseIf AddressTextBox.Text <> "" ThenSearch = AddressTextBox.Text
Column =
"Address" ElseIf CityTextBox.Text <> "" ThenSearch = CityTextBox.Text
Column =
"City" ElseIf PostalTextBox.Text <> "" ThenSearch = PostalTextBox.Text
Column =
"Postal" ElseIf PhoneTextBox.Text <> "" ThenSearch = PhoneTextBox.Text
Column =
"Phone" ElseIf MonthComboBox.Text <> "" ThenSearch = MonthComboBox.Text
Column =
"Month" End IfListBox1.Visible =
TrueMyConnection.Open()
MyParam.Value = Search
MyCommand.Parameters.Add(MyParam)
MyCommand.CommandText =
"Select [Column] from tblContacts Where [Column] = [Search]"MyCommand.Connection = MyConnection
MyReader = MyCommand.ExecuteReader
While MyReader.Read Me.ListBox1.Items.Add(MyReader(0)) End WhileMyConnection.Close()
yeos_lee
Thanks DMan1, now it works !
Just wanted to say sorry for the annoying posts asking very stupid questions. But you know i'm new to VB, and i hope i learn it some day.
C YA
tayoga
Use the ado.net connection, command, parameter, and sql string to retrieve the data
The exact syntax will vary depending upon the db and controls used....
pseudo:
Dim MyCommand as OledbCommand
Dim MyParam as OledbParameter
MyParameter = Me.Textbox1.Text
MyCOmmand.Parameters.Add(MyParam)
MyCommand.CommandText = "Select [Blue Number] From Main Where [Blue Number] = "
MyConnection.Open
MyReader = MyCOmmand.ExecuteReader
While MyReader.Read
Me.ListBox1.Items.Add(MyReader(0))
Loop
MyConnection.CLose
ExtinctPencil
Hi DMan1, thanks for replying.
Well, i still got some error. After modifing the code as below :
Dim MyCommand As New OleDb.OleDbCommand
Dim MyParam As New OleDb.OleDbParameter
Dim MyConnection As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mems.mdb")
Dim MyReader As OleDb.OleDbDataReader
MyConnection.Open()
MyParam.Value = Me.TextBox1.Text
MyCommand.Parameters.Add(MyParam)
MyCommand.CommandText = "Select [Blue] From Table1 Where [Blue] = "
MyReader = MyCommand.ExecuteReader
While MyReader.Read
Me.ListBox1.Items.Add(MyReader(0))
End While
MyConnection.Close()
I excuted the program and got a message box with a yellow arrow hilighting the line " MyReader = MyCommand.ExecuteReader ".
The error inside the box is " InvalidOperationException was unhandeled. ExcuteReader : Connection property has not been initialized ".
So, what do you suggest