|
-
Oct 31st, 2008, 03:44 AM
#1
Thread Starter
Lively Member
[RESOLVED] Error when entering search key in MS access database ado.net form?!
Hi everybody…
I’ve created ado.net access database project form contain 1 table and 5 field.
The Problem: The search button work only for the first click If I try to put another search key in the textbox and click the search button I’m getting an error code “This causes two bindings in the collection to bind to the same property. Parameter name: binding”
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
ExactSearch()
Conn.Open()
Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
DataAdapter1.Fill(DataSet1, "store")
Conn.Close()
tbSearchResulItemPartNumber.DataBindings.Add("Text", DataSet1, "store.Item Part Number")
tbSearchResultItemDeascriptions.DataBindings.Add("Text", DataSet1, "store.Item Descriptions")
tbSearchResultItemLocation.DataBindings.Add("Text", DataSet1, "store.Item Location")
DataGridView1.DataSource = DataSet1
DataGridView1.DataMember = "store"
If Me.BindingContext(DataSet1, "store").Count = 0 Then
MsgBox("No Result, Either the item part number incorrect format or the item not exist in the store ??!! ")
Form1.Show()
Me.Close()
End If
Exit Sub
End Sub
Public Sub ExactSearch()
SQLstr = "SELECT * FROM store WHERE [Item Part Number ]= '" & tbSearch.Text & "'"
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 suggestion codes to make the search button get result repeatedly (every time I click) and appear once (result)...
Regards...
Last edited by HOTFIX; Nov 2nd, 2008 at 02:48 PM.
-
Oct 31st, 2008, 04:21 AM
#2
Fanatic Member
Re: Error when entering search key in MS access database ado.net form?!
Just add this line before you do the DataBindigs
vb Code:
tbSearchResultItemDeascriptions.DataBindings.Clear()
You would be fine.
-
Oct 31st, 2008, 04:57 AM
#3
Thread Starter
Lively Member
Re: Error when entering search key in MS access database ado.net form?!
Thanks pvbangera for your help...
I put your suggested code
Code:
Private Sub btnSearch_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSearch.Click
tbSearchResultItemDeascriptions.DataBindings.Clear()
Static m As Integer = 0
If tbSearch.Text = Trim("") Then Exit Sub
ExactSearch()
Conn.Open()
Dim DataAdapter1 As New OleDbDataAdapter(SQLstr, Conn)
DataAdapter1.Fill(DataSet1, "store")
Conn.Close()
tbSearchResulItemPartNumber.DataBindings.Clear()
tbSearchResulItemPartNumber.DataBindings.Add("Text", DataSet1, "store.Item Part Number")
tbSearchResultItemDeascriptions.DataBindings.Clear()
tbSearchResultItemDeascriptions.DataBindings.Add("Text", DataSet1, "store.Item Descriptions")
tbSearchResultItemLocation.DataBindings.Clear()
tbSearchResultItemLocation.DataBindings.Add("Text", DataSet1, "store.Item Location")
DataGridView1.DataSource = DataSet1
DataGridView1.DataMember = "store"
If Me.BindingContext(DataSet1, "store").Count = 0 Then
MsgBox("No Result, Either the item part number incorrect format or the item not exist in the store ??!! ")
Form1.Show()
Me.Close()
End If
Exit Sub
End Sub
But still not working properly:
The details view didn't cleared & the grid view showing two recordes
Any other ideas please ?!
Regards...
Last edited by HOTFIX; Nov 2nd, 2008 at 02:46 PM.
-
Nov 1st, 2008, 11:30 AM
#4
Thread Starter
Lively Member
Re: Error when entering search key in MS access database ado.net form?!
Solved Out
Last edited by HOTFIX; Nov 2nd, 2008 at 02:47 PM.
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
|