|
-
Jan 8th, 2007, 09:09 AM
#1
Thread Starter
New Member
[RESOLVED] [2005] Ms
Pls help. Am tryin to retrieve data from a database using a query.
Private Sub Search_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Search.Click
'The OleDbDataReader is a forward-only data reader used for speed and efficiency.
Dim SQLReader As OleDbDataReader
'Dim Searchstr As String = ""
Dim Searchstr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\NRaqa\Desktop\TestD.mdb"
Dim conn As OleDbConnection
conn = New OleDbConnection(Searchstr)
Dim query As String = "Select NAME FROM KonkeQuery where NAME like '%storename.text%'"
Dim command As New OleDbCommand(query, conn)
If storename.Text = "" Then
MsgBox("Please Enter Strore name", MsgBoxStyle.Exclamation)
Exit Sub
Else
conn.Open()
SQLReader = command.ExecuteReader()
If SQLReader.HasRows Then
While SQLReader.Read
storename.Text = SQLReader.Item(query) <-------------this lne is bein skipped even if the user enters part of the string dat is d
End While
Else
MsgBox("There were no matches found, please try again", MsgBoxStyle.Information)
End If
conn.Close()
End If
End Sub
Thanks in advance
Regards
Noks
-
Jan 8th, 2007, 09:18 AM
#2
Fanatic Member
Re: [2005] Ms
I'm not 100% certain...but i think ur problem might be to do with your select statement because it looks like you are searching for the text 'storename.text' not what that contains. Have you tried changing that part of the statement to something you know will return a result? If you have then what did you try, what did it return and what should it have returned?
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Jan 8th, 2007, 09:42 AM
#3
Re: [2005] Ms
Missing quotes....should be
VB Code:
Dim query As String = "Select NAME FROM KonkeQuery where NAME like '%" & storename.text & "%'"
-
Jan 8th, 2007, 10:33 AM
#4
Fanatic Member
Re: [2005] Ms
Try changing:
VB Code:
storename.Text = SQLReader.Item(query)
to
VB Code:
storename.Text = SQLReader.Item("name")
because then it will return the value in that named column. If the column is called something else then change whats inside the quotes. Or you could use the column number if you know what it is going to be.
Also another thing i have noticed is that if there is going to be more than one result got back then it will only display the last result received in the textbox (assuming storename is a textbox), if you want to display all returned results then you will need to either say
VB Code:
storename.Text += SQLReader.Item("name") & controlchars.newline
Hope this helps
If your problem has been solved then please mark the thread [RESOLVED].
If i have helped then please Rate my post 
-
Jan 8th, 2007, 01:06 PM
#5
Hyperactive Member
Re: [2005] Ms
when in doubt do msgbox(query) and see then you can see what the sql server is getting and try it in the query manager.
Also a try catch block might be helpful
Try
storename.Text = SQLReader.Item(query)
Catch ex As Exception
'this will give you lots of good info!
MsgBox(ex.ToString)
End Try
-
Jan 9th, 2007, 01:05 AM
#6
Thread Starter
New Member
Re: [2005] Ms
Thanks guys... u've been a huge help.. now i get the results i want...Thanks 4 a gr8 welcome and not ignorin ma post
Regards Noks
Last edited by noks; Jan 9th, 2007 at 01:08 AM.
Reason: Misspellin
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
|