|
-
Oct 25th, 2008, 08:04 AM
#1
Thread Starter
Lively Member
[RESOLVED] Error in searching access database records by ado.net
Hi everybody…
I’ve made access database table using Microsoft Access 2007 and exported as aceess2000 .mdb file.
Table name: store
Table fields:
Item ID: AutoNumber
Item Part Number: Text
Item Descriptions: Text
Item Location: Text
Item Quantity: Text
Then I’ve made OleDb connection thorough vb.net 2008
After that I’ve added two type searches exact and general by radio button.
The problem is the search command return an error line “Syntax error (missing operator) in query expression”
Code:
Imports System.Data
Imports System.Data.OleDb
Public Class Form2
Dim frm As New Form1
Dim ConStr As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source =" & Application.StartupPath & "\data.mdb"
Dim Conn As New OleDbConnection(ConStr)
Dim DataSet1 As New DataSet
Dim SQLstr As String
Dim m As String
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
Static m As Integer = 0
If tbSearch.Text = Trim("") Then Exit Sub
If RadExactWord.Checked = True Then
ExactSearch()
ElseIf RadGeneralSearch.Checked = True Then
GeneralSearch()
End If
Conn.Open()
Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
DataAdapter1.Fill(DataSet1, "store")
Conn.Close()
tbPartNumberResult.DataBindings.Add("Text", DataSet1, "store.Item Part Number")
tbDescriptionsResult.DataBindings.Add("Text", DataSet1, "store.Item Descriptions")
tbLocationResult.DataBindings.Add("Text", DataSet1, "store.Item Location")
tbQTYresult.DataBindings.Add("Text", DataSet1, "store.Item Quantity")
DataGridView1.DataSource = DataSet1
DataGridView1.DataMember = "store"
If Me.BindingContext(DataSet1, "store").Count = 0 Then
MsgBox("No Result, Please Try Again ")
Exit Sub
End If
End Sub
Public Sub ExactSearch()
If RadItemPartNumber.Checked = True Then
SQLstr = "SELECT * FROM store WHERE Item Part Number = '" & tbSearch.Text & "' "
ElseIf RadItemDescriptions.Checked = True Then
SQLstr = "SELECT * FROM store WHERE Item Descriptions = '" & tbSearch.Text & "' "
End If
End Sub
Public Sub GeneralSearch()
If RadItemPartNumber.Checked = True Then
SQLstr = "SELECT * FROM store WHERE Item Part Number LIKE '%" & tbSearch.Text & "%'"
ElseIf RadItemDescriptions.Checked = True Then
SQLstr = "SELECT * FROM store WHERE Item Descriptions LIKE '%" & tbSearch.Text & "%'"
End If
End Sub
Private Sub btnBACK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnBACK.Click
Me.Close()
Form1.Show()
End Sub
End Class
Any help for correcting codes
Regrads
Last edited by HOTFIX; Dec 14th, 2008 at 12:51 PM.
-
Oct 25th, 2008, 10:49 AM
#2
Re: Error in searching access database records by ado.net
Field names that include spaces need to be enclosed in square brackets within a query string.
WHERE [Item Part Number] LIKE
WHERE [Item Descriptions] LIKE
-
Oct 25th, 2008, 11:05 AM
#3
Thread Starter
Lively Member
Re: Error in searching access database records by ado.net
 Originally Posted by brucevde
Field names that include spaces need to be enclosed in square brackets within a query string.
WHERE [Item Part Number] LIKE
WHERE [Item Descriptions] LIKE
MANY THANKS brucevde
It's Working
Best Regrads...
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
|