|
-
Feb 7th, 2003, 08:08 AM
#1
Thread Starter
Sleep mode
darn it , no action at all [UN -Resolved yet]
Hell , I dunno what the **** is going wrong with this code , no action at all .I hate it .Basically , I want to search my database.anyone has example or a link ....thanx for any help .
VB Code:
Private Sub Button2_Click(ByVal sender As System.Object _
, ByVal e As System.EventArgs) Handles Button2.Click
Dim MyConnection1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
MyPath & ";Jet OLEDB:Database Password=" & MyPassword)
Dim myDataReader As OleDbDataReader
Dim txt As String = "SELECT * FROM MyTab WHERE C_URL LIKE '" & TextBox7.Text.Replace("'", "''") & "*'"
Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1)
MyConnection1.Open()
myDataReader = myOleDbCommand.ExecuteReader()
Do While (myDataReader.Read)
If (myDataReader.IsDBNull(0)) Then
MsgBox(myDataReader.GetString(1))
Console.Write("N/A" + Chr(10))
MsgBox("no data")
Else
Console.Write(myDataReader.GetInt32(4).ToString() + Chr(10))
MsgBox(myDataReader.GetInt32(4).ToString() + Chr(10))
End If
Loop
myDataReader.Close()
MyConnection1.Close()
End Sub
Last edited by Pirate; Feb 7th, 2003 at 11:31 AM.
-
Feb 7th, 2003, 08:55 AM
#2
Thread Starter
Sleep mode
even C# code is accepted !
-
Feb 7th, 2003, 12:10 PM
#3
Thread Starter
Sleep mode
-
Feb 8th, 2003, 08:03 AM
#4
Addicted Member
Code:
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim MyConnection1 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
MyPath & ";Jet OLEDBatabase Password=" & MyPassword)
Dim myDataReader As OleDbDataReader
Dim txt As String = "SELECT * FROM MyTab WHERE C_URL LIKE '" & TextBox7.Text.Replace("'", "''") & "*'"
Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1)
MyConnection1.Open()
myDataReader = myOleDbCommand.ExecuteReader()
Do While (myDataReader.Read)
If (myDataReader.IsDBNull(0)) Then
MsgBox(myDataReader.GetString(1))
Console.Write("N/A" + Chr(10))
MsgBox("no data")
Else
Console.Write(myDataReader.GetInt32(4).ToString() + Chr(10))
MsgBox(myDataReader.GetInt32(4).ToString() + Chr(10))
End If
Loop
myDataReader.Close()
MyConnection1.Close()
End Sub
Some things in your code are not totally clear .....
1: Jet OLEDBatabase Password= never seen this param before, try to use UID=Admin;PWD=mypassword
I used user ID Admin here. u should use this for sure if you are using a MS Access database.
Code:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
MyPath & ";Jet OLEDBatabase Password=" & MyPassword
Code:
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
MyPath & ";UID=Admin;PWD=" & MyPassword
===
2. Try to swap next 2 rules, open your dataconnection before creating the Command Object. Add the connection object to the New OleDBCommand rules to give the connction object to the command object.
Code:
Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1)
MyConnection1.Open()
Code:
MyConnection1.Open()
Dim myOleDbCommand = New OleDbCommand(txt, MyConnection1, MyConnection1)
===
3. Im allways using SQL Databases (used access long time ago)
For Like clauses an asterix char will not work. I guess thats the same in access and most other databases. To search, use % instead of *
===
I hope these changes make you app work.
Greets Nightmare 
http://www.nightmare-products.com (Under construction)
[email protected]
-
Feb 8th, 2003, 11:03 AM
#5
Thread Starter
Sleep mode
Thanx for your the reply Nigh™a®e .I got another problem which says : "Couldn't find installable ISAM" .Open connection is highlighted . What's going wrong !
I wish anyone gets me another way to search for records !
-
Feb 10th, 2003, 12:36 AM
#6
Member
I would be glad (as most of us would be I imagine) to take a look at it if you could post it.
If that is not an option (understandable if it isn't) then may I suggest putting in some Try...Catch...End Try statements to possibly give you "more meaningful" error messages to help narrow the root cause. I have found this QUITE helpful when using databases.
Eagle Eye
"Programming is easy ... when you are done."
-
Feb 10th, 2003, 11:45 AM
#7
Thread Starter
Sleep mode
Well , I always use the structure try ....catch to handle exceptions but I just can't seem to solve the problem .It must be something wrong with the connection string but it looks fine .Searching database in ADO.NET is a real pain !
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|