By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,534 Members | 865 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,534 IT Pros & Developers. It's quick & easy.

Search thrue Database

P: n/a
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!!

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #1
Share this Question
Share on Google+
3 Replies


P: n/a
"Animal" <di**@phantoms-dot-nl.no-spam.invalid> schrieb
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

Nov 20 '05 #2

P: n/a
> Armin Zinglerwrote:
"Animal" <di**@phantoms-dot-nl.no-spam.invalid> schrieb
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!!

----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---
Nov 20 '05 #3

P: n/a
"Animal" <di**@phantoms-dot-nl.no-spam.invalid> schrieb
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.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.