Question : Error Converting DataType VarChar to Numeric - DataSet - Detail - ToolStripTextBox

VB 2008 NOT Working correctly, WHY?
I have a VB Studio 2008 Pro and SQL 2005 with a Table with Record ID (Patron_ID) that is Numeric and other fields that are varchar.

I created a dataset accessing the Table, then selected Detail for the table fields, then dragged the table onto a form.

I created a Query for each Field.

Example for Patron_ID: "SELECT Patron_ID, Family_Name, Address, City, State, Zip_Code, Membership_Date, Renewal_Date, Modified_Date FROM dbo.P_Main WHERE (Patron_ID LIKE @Patron_ID + '%') ORDER BY Patron_ID"

When I perform a search using the FillBy_ToolStrip, I get the following error and ONLY for the Record ID is "Error converting Datatype VarChar to Numeric".

But all the other fields work....WHY?

What and where do I need to change or write code to make it work.

Attached is the code from the form. The code was created by VB 2008.

Looking forward to suggestions and resolution.

Thanks and Happy New Year to ALL

ITCS Admin
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
141:
142:
143:
144:
145:
146:
147:
Public Class wfPatron_Main
 
    Private Sub wfPatron_Main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'TODO: This line of code loads data into the 'DataSet_Patron_Main_SEARCH.P_Main' table. You can move, or remove it, as needed.
        Me.TableAdapter_Patron_Main_SEARCH.Fill(Me.DataSet_Patron_Main_SEARCH.P_Main)
        Me.TableAdapter_Patron_Members.Fill(Me.DataSet_Patron_Main.P_Members)
 
    End Sub
 
    Private Sub Patron_Main_BN_SaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Validate()
        Me.BindingSource_Patron_Main.EndEdit()
        Me.BindingSource_Patron_Members.EndEdit()
        Me.TableAdapterManager_Patron_Main.UpdateAll(Me.DataSet_Patron_Main)
 
    End Sub
 
    Private Sub BindingSource_Patron_Members_AddingNew(ByVal sender As Object, ByVal e As System.ComponentModel.AddingNewEventArgs) Handles BindingSource_Patron_Members.AddingNew
        Me.BindingSource_Patron_Members.EndEdit()
 
    End Sub
 
    Private Sub FillBy_Patron_IDToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBy_Patron_IDToolStrip.Click
        Try
            Me.TableAdapter_Patron_Main.FillBy_Patron_ID(Me.DataSet_Patron_Main.P_Main, CType(Patron_IDToolStripTextBox.Text, Decimal))
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
 
        'Private Sub FillBy_Patron_IDToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBy_Patron_IDToolStripButton.Click
        '    Try
        '        'Patron_IDToolStripTextBox.Text = "104111"
        '        MsgBox(Patron_IDToolStripTextBox.Text)
        '        MsgBox(CType(Patron_IDToolStripTextBox.Text, Decimal))
        '        Me.TableAdapter_Patron_Main.FillBy_Patron_ID(Me.DataSet_Patron_Main.P_Main, CType(Patron_IDToolStripTextBox.Text, Decimal))
        '        'Me.TableAdapter_Patron_Main.FillBy_Patron_ID(Me.DataSet_Patron_Main.P_Main, Patron_IDToolStripTextBox.Text.ToString)
        '    Catch ex As System.Exception
        '        System.Windows.Forms.MessageBox.Show(ex.Message)
        '    End Try
 
    End Sub
 
    Private Sub FillBy_Family_NameToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBy_Family_NameToolStripButton.Click
        Try
            Me.TableAdapter_Patron_Main.FillBy_Family_NAme(Me.DataSet_Patron_Main.P_Main, Family_NameToolStripTextBox.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
 
    End Sub
 
    Private Sub FillBy_AddressToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBy_AddressToolStripButton.Click
        Try
            Me.TableAdapter_Patron_Main.FillBy_Address(Me.DataSet_Patron_Main.P_Main, AddressToolStripTextBox.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
 
    End Sub
 
    Private Sub FillBy_CityToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBy_CityToolStripButton.Click
        Try
            Me.TableAdapter_Patron_Main.FillBy_City(Me.DataSet_Patron_Main.P_Main, CityToolStripTextBox.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
 
    End Sub
 
    Private Sub FillBy_StateToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBy_StateToolStripButton.Click
        Try
            Me.TableAdapter_Patron_Main.FillBy_State(Me.DataSet_Patron_Main.P_Main, StateToolStripTextBox.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
 
    End Sub
 
    Private Sub FillBy_Zip_CodeToolStripButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles FillBy_Zip_CodeToolStripButton.Click
        Try
            Me.TableAdapter_Patron_Main.FillBy_Zip_Code(Me.DataSet_Patron_Main.P_Main, Zip_CodeToolStripTextBox.Text)
        Catch ex As System.Exception
            System.Windows.Forms.MessageBox.Show(ex.Message)
        End Try
 
    End Sub
 
    Private Sub Patron_Main_BN_SearchItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Patron_Main_BN_SearchItem.Click
        If AP_Patron_ID_TextBox.Text <> "" Then
            FillBy_Patron_IDToolStripButton.PerformClick()
        ElseIf AP_Family_Name_TextBox.Text <> "" Then
            FillBy_Family_NameToolStripButton.PerformClick()
        ElseIf AP_Address_TextBox.Text <> "" Then
            FillBy_AddressToolStripButton.PerformClick()
        ElseIf AP_City_TextBox.Text <> "" Then
            FillBy_CityToolStripButton.PerformClick()
        ElseIf AP_State_TextBox.Text <> "" Then
            FillBy_StateToolStripButton.PerformClick()
        ElseIf AP_Zip_Code_TextBox.Text <> "" Then
            FillBy_Zip_CodeToolStripButton.PerformClick()
        End If
    End Sub
 
    Private Sub AP_Patron_ID_TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AP_Patron_ID_TextBox.TextChanged
        Patron_IDToolStripTextBox.Text = AP_Patron_ID_TextBox.Text
 
    End Sub
 
    Private Sub AP_Family_Name_TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AP_Family_Name_TextBox.TextChanged
        Family_NameToolStripTextBox.Text = AP_Family_Name_TextBox.Text
    End Sub
 
    Private Sub AP_Address_TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AP_Address_TextBox.TextChanged
        AddressToolStripTextBox.Text = AP_Address_TextBox.Text
    End Sub
 
    Private Sub AP_City_TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AP_City_TextBox.TextChanged
        CityToolStripTextBox.Text = AP_City_TextBox.Text
    End Sub
 
    Private Sub AP_State_TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AP_State_TextBox.TextChanged
        StateToolStripTextBox.Text = AP_State_TextBox.Text
    End Sub
 
    Private Sub AP_Zip_Code_TextBox_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AP_Zip_Code_TextBox.TextChanged
        Zip_CodeToolStripTextBox.Text = AP_Zip_Code_TextBox.Text
    End Sub
 
    Private Sub Patron_Main_BN_ClearItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Patron_Main_BN_ClearItem.Click
        AP_Patron_ID_TextBox.Clear()
        AP_Family_Name_TextBox.Clear()
        AP_Address_TextBox.Clear()
        AP_City_TextBox.Clear()
        AP_State_TextBox.Clear()
        AP_Zip_Code_TextBox.Clear()
        AP_Membership_Date_TextBox.Clear()
        AP_Renewal_Date_TextBox.Clear()
        AP_Modified_Date_TextBox.Clear()
    End Sub
 
    Private Sub Patron_Main_BN_DetailItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Patron_Main_BN_DetailItem.Click
        Dim f As New wfPatron_Member
        f.Show()
 
    End Sub
 
End Class

Answer : Error Converting DataType VarChar to Numeric - DataSet - Detail - ToolStripTextBox

You have to make the parameters optional and construct your call so that it passes NULL in when you don't need that parameter.
Random Solutions  
 
programming4us programming4us