Search thrue Database

  • Thread starter Thread starter Animal
  • Start date Start date
A

Animal

Hey,

I've got the following problem: I'm trying to create a small tool that
must be able to search thrue a database using a search-criteria, that
has to be entered by the user in a TextBox. The results of the search
are displayed in a small datagrid.
My problem is that I've no idea how to create the search functionality
with VB.NET. The datadase used is a smal access database.
Maybe one of you can give me a hint....

Thnx!!
 
Animal said:
I've got the following problem: I'm trying to create a small tool
that must be able to search thrue a database using a search-criteria,
that has to be entered by the user in a TextBox. The results of the
search are displayed in a small datagrid.
My problem is that I've no idea how to create the search
functionality with VB.NET. The datadase used is a smal access
database. Maybe one of you can give me a hint....

Maybe I misunderstood...

Use ADO.NET to access the database. Some Keywords:
- System.Data.OleDb.OleDbConnection
- System.Data.OleDb.OleDbCommand
- System.Data.OleDb.OleDbDataReader
- System.Data.DataSet

More ADO.NET:
<F1>
VS.NET
.NET Framework
Programming with .NET Framework
-> Accessing Data
VB and VC#
-> Accessing Data


ADO.NET group: microsoft.public.dotnet.framework.adonet
 
Armin Zinglerwrote:
Animal said:
I've got the following problem: I'm trying to create a small tool
that must be able to search thrue a database using a search-criteria,
that has to be entered by the user in a TextBox. The results of the
search are displayed in a small datagrid.
My problem is that I've no idea how to create the search
functionality with VB.NET. The datadase used is a smal access
database. Maybe one of you can give me a hint....
Maybe I misunderstood...

Use ADO.NET to access the database. Some Keywords:
- System.Data.OleDb.OleDbConnection
- System.Data.OleDb.OleDbCommand
- System.Data.OleDb.OleDbDataReader
- System.Data.DataSet

More ADO.NET:
<F1>
VS.NET
.NET Framework
Programming with .NET Framework
-> Accessing Data
VB and VC#
-> Accessing Data


ADO.NET group: microsoft.public.dotnet.framework.adonet


--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html[/quote:eaaae8d79c]

Armin,

Thnx for the hint!
This is what I tried. The code is based on an example given on the
Microsoft site:


Public Sub ReadMyData(ByVal myConnString As String)
Dim mySelectQuery As String = "SELECT Doc ID, Subject,
Title, created " & _
"FROM Document WHERE Title LIKE " &
TextBox1.Text
Dim myConnection As New
OleDb.OleDbConnection(myConnString)
Dim myCommand As New OleDb.OleDbCommand(mySelectQuery,
myConnection)
myConnection.Open()
Dim myReader As OleDb.OleDbDataReader =
myCommand.ExecuteReader()
Try
While myReader.Read()

Console.WriteLine(myReader.GetInt32(0).ToString()
+ ", " _
+ myReader.GetString(1))
End While
Finally
' always call Close when done reading.
myReader.Close()
' always call Close when done reading.
myConnection.Close()
End Try
End Sub


The sub is called by a click on a button.
As soon as the sub is called I'll get the following error:

"An unhandled exception of typ "System.Data.OleDb.OleDbException"
occured in system.data.dll"

The exception gets raised on the line containing:
[code:1:eaaae8d79c]Dim myReader As OleDb.OleDbDataReader =
myCommand.ExecuteReader()[/code:1:eaaae8d79c]

Does anybody has an idea why this exception is raised??

Thnx!!




http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
 
Animal said:
Public Sub ReadMyData(ByVal myConnString As String)
Dim mySelectQuery As String = "SELECT Doc ID, Subject,
Title, created " & _
"FROM Document WHERE Title LIKE " &
TextBox1.Text
Dim myConnection As New
OleDb.OleDbConnection(myConnString)
Dim myCommand As New OleDb.OleDbCommand(mySelectQuery,
myConnection)
myConnection.Open()
Dim myReader As OleDb.OleDbDataReader =
myCommand.ExecuteReader()
Try
While myReader.Read()

Console.WriteLine(myReader.GetInt32(0).ToString()
+ ", " _
+ myReader.GetString(1))
End While
Finally
' always call Close when done reading.
myReader.Close()
' always call Close when done reading.
myConnection.Close()
End Try
End Sub


The sub is called by a click on a button.
As soon as the sub is called I'll get the following error:

"An unhandled exception of typ "System.Data.OleDb.OleDbException"
occured in system.data.dll"

The exception gets raised on the line containing:
[code:1:eaaae8d79c]Dim myReader As OleDb.OleDbDataReader =
myCommand.ExecuteReader()[/code:1:eaaae8d79c]

Does anybody has an idea why this exception is raised??


You can catch the exception and examine it. Probably there's a syntax error
in the SQL string. Have a look at it.
 
Back
Top