Trying to INSERT values into a SQL database

diverdan

Active member
Joined
Jan 2, 2006
Messages
34
Location
London UK
Programming Experience
Beginner
Hi there,

Hoping someone can help me out with a problem I am having while trying to insert information into a database.

I am pretty new to this and I have taken this code from a WROX beginning vb.net 2003 book and tried to modify it to suit.

When I try excute the code I get an error box saying...
An unhandled exception of type 'System.ArgumentException' occurred in system.windows.forms.dll

Additional information: This would cause two bindings in the collection to bind to the same property.
This is my code
VB.NET:
Imports System.Data
Imports System.Data.SqlClient



Public Class frmCustomers
    Inherits System.Windows.Forms.Form
    Dim objConnection As SqlConnection = New _
        SqlConnection("server= nx6130;database=actionglass;user id=sa;Trusted_Connection=True;")
    Dim objDataAdapter As SqlDataAdapter = New SqlDataAdapter( _
        "SELECT tblCustomers.CustomerName,ContactName,PhoneNumber,FaxNumber,MobNumber,EmailAddress,Address1,Address2,Address3,Address4,DAddress1,DAddress2,DAddress3,DAddress4 " & _
        "FROM tblCustomers " & _
        "ORDER BY CustomerName", objConnection)
    Dim objDataSet As DataSet
    Dim objDataView As DataView
    Dim objCurrencyManager As CurrencyManager




    Private Sub FillDataSetAndView()

        objDataSet = New DataSet
        objDataAdapter.Fill(objDataSet, "tblCustomers")

        objDataView = New DataView(objDataSet.Tables("tblCustomers"))
        objCurrencyManager = CType(Me.BindingContext(objDataView), CurrencyManager)

    End Sub

    Private Sub ShowPosition()
        txtRecordPosition.Text = objCurrencyManager.Position + 1 & _
        " of " & objCurrencyManager.Count()

    End Sub

#Region " Windows Form Designer generated code "

    '/// this will allow you to access whichever form called you ( eg : Form1 )
    Private frm As Form
    Public Sub New(ByVal f As Form)
        MyBase.New()
        frm = f
        'This call is required by the Windows Form Designer.
        InitializeComponent()
        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents lblCustomerName As System.Windows.Forms.Label
    Friend WithEvents txtCustomerName As System.Windows.Forms.TextBox
    Friend WithEvents btn1st As System.Windows.Forms.Button
    Friend WithEvents btnPrevious As System.Windows.Forms.Button
    Friend WithEvents btnNext As System.Windows.Forms.Button
    Friend WithEvents txtPhoneNumber As System.Windows.Forms.TextBox
    Friend WithEvents lblPhoneNumber As System.Windows.Forms.Label
    Friend WithEvents txtFaxNumber As System.Windows.Forms.TextBox
    Friend WithEvents lblFaxNumber As System.Windows.Forms.Label
    Friend WithEvents lblCustomerContact As System.Windows.Forms.Label
    Friend WithEvents txtAddress2 As System.Windows.Forms.TextBox
    Friend WithEvents lblAddress2 As System.Windows.Forms.Label
    Friend WithEvents txtAddress1 As System.Windows.Forms.TextBox
    Friend WithEvents lblAddress1 As System.Windows.Forms.Label
    Friend WithEvents txtEmailAddress As System.Windows.Forms.TextBox
    Friend WithEvents lblEmailAddress As System.Windows.Forms.Label
    Friend WithEvents lblMobileNumber As System.Windows.Forms.Label
    Friend WithEvents txtAddress4 As System.Windows.Forms.TextBox
    Friend WithEvents lblAddress4 As System.Windows.Forms.Label
    Friend WithEvents txtAddress3 As System.Windows.Forms.TextBox
    Friend WithEvents lblAddress3 As System.Windows.Forms.Label
    Friend WithEvents lblBillingAddress1 As System.Windows.Forms.Label
    Friend WithEvents lblBillingAddress2 As System.Windows.Forms.Label
    Friend WithEvents lblBillingAddress3 As System.Windows.Forms.Label
    Friend WithEvents lblBillingAddress As System.Windows.Forms.Label
    Friend WithEvents P As System.Windows.Forms.TabControl
    Friend WithEvents tabInvoices As System.Windows.Forms.TabPage
    Friend WithEvents tabQuotes As System.Windows.Forms.TabPage
    Friend WithEvents grdCustomers As System.Windows.Forms.DataGrid
    Friend WithEvents btnNewSale As System.Windows.Forms.Button
    Friend WithEvents btnQuote As System.Windows.Forms.Button
    Friend WithEvents StatusBar1 As System.Windows.Forms.StatusBar
    Friend WithEvents txtContactName As System.Windows.Forms.TextBox
    Friend WithEvents txtMobNumber As System.Windows.Forms.TextBox
    Friend WithEvents txtDAddress1 As System.Windows.Forms.TextBox
    Friend WithEvents txtDAddress2 As System.Windows.Forms.TextBox
    Friend WithEvents txtDAddress3 As System.Windows.Forms.TextBox
    Friend WithEvents txtDAddress4 As System.Windows.Forms.TextBox
    Friend WithEvents txtRecordPosition As System.Windows.Forms.TextBox
    Friend WithEvents btnLast As System.Windows.Forms.Button
    Friend WithEvents btnAdd As System.Windows.Forms.Button
    Friend WithEvents btnSave As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.grdCustomers = New System.Windows.Forms.DataGrid
        Me.lblCustomerName = New System.Windows.Forms.Label
        Me.txtCustomerName = New System.Windows.Forms.TextBox
        Me.btn1st = New System.Windows.Forms.Button
        Me.btnPrevious = New System.Windows.Forms.Button
        Me.btnNext = New System.Windows.Forms.Button
        Me.btnLast = New System.Windows.Forms.Button
        Me.txtPhoneNumber = New System.Windows.Forms.TextBox
        Me.lblPhoneNumber = New System.Windows.Forms.Label
        Me.txtFaxNumber = New System.Windows.Forms.TextBox
        Me.lblFaxNumber = New System.Windows.Forms.Label
        Me.txtContactName = New System.Windows.Forms.TextBox
        Me.lblCustomerContact = New System.Windows.Forms.Label
        Me.txtAddress2 = New System.Windows.Forms.TextBox
        Me.lblAddress2 = New System.Windows.Forms.Label
        Me.txtAddress1 = New System.Windows.Forms.TextBox
        Me.lblAddress1 = New System.Windows.Forms.Label
        Me.txtEmailAddress = New System.Windows.Forms.TextBox
        Me.lblEmailAddress = New System.Windows.Forms.Label
        Me.txtMobNumber = New System.Windows.Forms.TextBox
        Me.lblMobileNumber = New System.Windows.Forms.Label
        Me.txtAddress4 = New System.Windows.Forms.TextBox
        Me.lblAddress4 = New System.Windows.Forms.Label
        Me.txtAddress3 = New System.Windows.Forms.TextBox
        Me.lblAddress3 = New System.Windows.Forms.Label
        Me.lblBillingAddress1 = New System.Windows.Forms.Label
        Me.txtDAddress1 = New System.Windows.Forms.TextBox
        Me.lblBillingAddress2 = New System.Windows.Forms.Label
        Me.txtDAddress2 = New System.Windows.Forms.TextBox
        Me.lblBillingAddress3 = New System.Windows.Forms.Label
        Me.txtDAddress3 = New System.Windows.Forms.TextBox
        Me.lblBillingAddress = New System.Windows.Forms.Label
        Me.txtDAddress4 = New System.Windows.Forms.TextBox
        Me.P = New System.Windows.Forms.TabControl
        Me.tabInvoices = New System.Windows.Forms.TabPage
        Me.tabQuotes = New System.Windows.Forms.TabPage
        Me.btnNewSale = New System.Windows.Forms.Button
        Me.btnQuote = New System.Windows.Forms.Button
        Me.StatusBar1 = New System.Windows.Forms.StatusBar
        Me.txtRecordPosition = New System.Windows.Forms.TextBox
        Me.btnAdd = New System.Windows.Forms.Button
        Me.btnSave = New System.Windows.Forms.Button
        CType(Me.grdCustomers, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.P.SuspendLayout()
        Me.tabQuotes.SuspendLayout()
        Me.SuspendLayout()
        '
        'grdCustomers
        '
        Me.grdCustomers.DataMember = ""
        Me.grdCustomers.HeaderForeColor = System.Drawing.SystemColors.ControlText
        Me.grdCustomers.Location = New System.Drawing.Point(32, 16)
        Me.grdCustomers.Name = "grdCustomers"
        Me.grdCustomers.Size = New System.Drawing.Size(984, 288)
        Me.grdCustomers.TabIndex = 0
        '
        'lblCustomerName
        '
        Me.lblCustomerName.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCustomerName.Location = New System.Drawing.Point(16, 16)
        Me.lblCustomerName.Name = "lblCustomerName"
        Me.lblCustomerName.Size = New System.Drawing.Size(120, 23)
        Me.lblCustomerName.TabIndex = 2
        Me.lblCustomerName.Text = "Customer Name :"
        '
        'txtCustomerName
        '
        Me.txtCustomerName.Location = New System.Drawing.Point(144, 16)
        Me.txtCustomerName.Name = "txtCustomerName"
        Me.txtCustomerName.TabIndex = 3
        Me.txtCustomerName.Text = ""
        '
        'btn1st
        '
        Me.btn1st.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btn1st.Location = New System.Drawing.Point(360, 264)
        Me.btn1st.Name = "btn1st"
        Me.btn1st.Size = New System.Drawing.Size(32, 23)
        Me.btn1st.TabIndex = 4
        Me.btn1st.Text = "|<<"
        '
        'btnPrevious
        '
        Me.btnPrevious.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnPrevious.Location = New System.Drawing.Point(408, 264)
        Me.btnPrevious.Name = "btnPrevious"
        Me.btnPrevious.Size = New System.Drawing.Size(32, 23)
        Me.btnPrevious.TabIndex = 5
        Me.btnPrevious.Text = "<"
        '
        'btnNext
        '
        Me.btnNext.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnNext.Location = New System.Drawing.Point(456, 264)
        Me.btnNext.Name = "btnNext"
        Me.btnNext.Size = New System.Drawing.Size(32, 23)
        Me.btnNext.TabIndex = 6
        Me.btnNext.Text = ">"
        '
        'btnLast
        '
        Me.btnLast.Font = New System.Drawing.Font("Microsoft Sans Serif", 8.25!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnLast.Location = New System.Drawing.Point(504, 264)
        Me.btnLast.Name = "btnLast"
        Me.btnLast.Size = New System.Drawing.Size(32, 23)
        Me.btnLast.TabIndex = 7
        Me.btnLast.Text = ">>|"
        '
        'txtPhoneNumber
        '
        Me.txtPhoneNumber.Location = New System.Drawing.Point(144, 80)
        Me.txtPhoneNumber.Name = "txtPhoneNumber"
        Me.txtPhoneNumber.TabIndex = 9
        Me.txtPhoneNumber.Text = ""
        '
        'lblPhoneNumber
        '
        Me.lblPhoneNumber.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblPhoneNumber.Location = New System.Drawing.Point(16, 80)
        Me.lblPhoneNumber.Name = "lblPhoneNumber"
        Me.lblPhoneNumber.Size = New System.Drawing.Size(120, 23)
        Me.lblPhoneNumber.TabIndex = 8
        Me.lblPhoneNumber.Text = "Phone Number :"
        '
        'txtFaxNumber
        '
        Me.txtFaxNumber.Location = New System.Drawing.Point(144, 112)
        Me.txtFaxNumber.Name = "txtFaxNumber"
        Me.txtFaxNumber.TabIndex = 13
        Me.txtFaxNumber.Text = ""
        '
        'lblFaxNumber
        '
        Me.lblFaxNumber.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblFaxNumber.Location = New System.Drawing.Point(16, 112)
        Me.lblFaxNumber.Name = "lblFaxNumber"
        Me.lblFaxNumber.Size = New System.Drawing.Size(120, 23)
        Me.lblFaxNumber.TabIndex = 12
        Me.lblFaxNumber.Text = "Fax Number :"
        '
        'txtContactName
        '
        Me.txtContactName.Location = New System.Drawing.Point(144, 48)
        Me.txtContactName.Name = "txtContactName"
        Me.txtContactName.TabIndex = 11
        Me.txtContactName.Text = ""
        '
        'lblCustomerContact
        '
        Me.lblCustomerContact.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblCustomerContact.Location = New System.Drawing.Point(16, 48)
        Me.lblCustomerContact.Name = "lblCustomerContact"
        Me.lblCustomerContact.Size = New System.Drawing.Size(120, 23)
        Me.lblCustomerContact.TabIndex = 10
        Me.lblCustomerContact.Text = "Contact Name :"
        '
        'txtAddress2
        '
        Me.txtAddress2.Location = New System.Drawing.Point(144, 240)
        Me.txtAddress2.Name = "txtAddress2"
        Me.txtAddress2.TabIndex = 22
        Me.txtAddress2.Text = ""
        '
        'lblAddress2
        '
        Me.lblAddress2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblAddress2.Location = New System.Drawing.Point(16, 240)
        Me.lblAddress2.Name = "lblAddress2"
        Me.lblAddress2.Size = New System.Drawing.Size(120, 23)
        Me.lblAddress2.TabIndex = 21
        Me.lblAddress2.Text = "Address 2 :"
        '
        'txtAddress1
        '
        Me.txtAddress1.Location = New System.Drawing.Point(144, 208)
        Me.txtAddress1.Name = "txtAddress1"
        Me.txtAddress1.TabIndex = 20
        Me.txtAddress1.Text = ""
        '
        'lblAddress1
        '
        Me.lblAddress1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblAddress1.Location = New System.Drawing.Point(16, 208)
        Me.lblAddress1.Name = "lblAddress1"
        Me.lblAddress1.Size = New System.Drawing.Size(120, 23)
        Me.lblAddress1.TabIndex = 19
        Me.lblAddress1.Text = "Address 1 :"
        '
        'txtEmailAddress
        '
        Me.txtEmailAddress.Location = New System.Drawing.Point(144, 176)
        Me.txtEmailAddress.Name = "txtEmailAddress"
        Me.txtEmailAddress.TabIndex = 18
        Me.txtEmailAddress.Text = ""
        '
        'lblEmailAddress
        '
        Me.lblEmailAddress.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblEmailAddress.Location = New System.Drawing.Point(16, 176)
        Me.lblEmailAddress.Name = "lblEmailAddress"
        Me.lblEmailAddress.Size = New System.Drawing.Size(120, 23)
        Me.lblEmailAddress.TabIndex = 17
        Me.lblEmailAddress.Text = "Email Address :"
        '
        'txtMobNumber
        '
        Me.txtMobNumber.Location = New System.Drawing.Point(144, 144)
        Me.txtMobNumber.Name = "txtMobNumber"
        Me.txtMobNumber.TabIndex = 16
        Me.txtMobNumber.Text = ""
        '
        'lblMobileNumber
        '
        Me.lblMobileNumber.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblMobileNumber.Location = New System.Drawing.Point(16, 144)
        Me.lblMobileNumber.Name = "lblMobileNumber"
        Me.lblMobileNumber.Size = New System.Drawing.Size(120, 23)
        Me.lblMobileNumber.TabIndex = 15
        Me.lblMobileNumber.Text = "Mob Number :"
        '
        'txtAddress4
        '
        Me.txtAddress4.Location = New System.Drawing.Point(144, 304)
        Me.txtAddress4.Name = "txtAddress4"
        Me.txtAddress4.TabIndex = 26
        Me.txtAddress4.Text = ""
        '
        'lblAddress4
        '
        Me.lblAddress4.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblAddress4.Location = New System.Drawing.Point(16, 304)
        Me.lblAddress4.Name = "lblAddress4"
        Me.lblAddress4.Size = New System.Drawing.Size(120, 23)
        Me.lblAddress4.TabIndex = 25
        Me.lblAddress4.Text = "Address 4 :"
        '
        'txtAddress3
        '
        Me.txtAddress3.Location = New System.Drawing.Point(144, 272)
        Me.txtAddress3.Name = "txtAddress3"
        Me.txtAddress3.TabIndex = 24
        Me.txtAddress3.Text = ""
        '
        'lblAddress3
        '
        Me.lblAddress3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblAddress3.Location = New System.Drawing.Point(16, 272)
        Me.lblAddress3.Name = "lblAddress3"
        Me.lblAddress3.Size = New System.Drawing.Size(120, 23)
        Me.lblAddress3.TabIndex = 23
        Me.lblAddress3.Text = "Address 3 :"
        '
        'lblBillingAddress1
        '
        Me.lblBillingAddress1.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblBillingAddress1.Location = New System.Drawing.Point(280, 16)
        Me.lblBillingAddress1.Name = "lblBillingAddress1"
        Me.lblBillingAddress1.Size = New System.Drawing.Size(120, 23)
        Me.lblBillingAddress1.TabIndex = 28
        Me.lblBillingAddress1.Text = "Billing Address 1 :"
        '
        'txtDAddress1
        '
        Me.txtDAddress1.Location = New System.Drawing.Point(408, 16)
        Me.txtDAddress1.Name = "txtDAddress1"
        Me.txtDAddress1.TabIndex = 29
        Me.txtDAddress1.Text = ""
        '
        'lblBillingAddress2
        '
        Me.lblBillingAddress2.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblBillingAddress2.Location = New System.Drawing.Point(280, 48)
        Me.lblBillingAddress2.Name = "lblBillingAddress2"
        Me.lblBillingAddress2.Size = New System.Drawing.Size(120, 23)
        Me.lblBillingAddress2.TabIndex = 30
        Me.lblBillingAddress2.Text = "Billing Address 2 :"
        '
        'txtDAddress2
        '
        Me.txtDAddress2.Location = New System.Drawing.Point(408, 48)
        Me.txtDAddress2.Name = "txtDAddress2"
        Me.txtDAddress2.TabIndex = 31
        Me.txtDAddress2.Text = ""
        '
        'lblBillingAddress3
        '
        Me.lblBillingAddress3.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblBillingAddress3.Location = New System.Drawing.Point(280, 80)
        Me.lblBillingAddress3.Name = "lblBillingAddress3"
        Me.lblBillingAddress3.Size = New System.Drawing.Size(120, 23)
        Me.lblBillingAddress3.TabIndex = 32
        Me.lblBillingAddress3.Text = "Billing Address 3 :"
        '
        'txtDAddress3
        '
        Me.txtDAddress3.Location = New System.Drawing.Point(408, 80)
        Me.txtDAddress3.Name = "txtDAddress3"
        Me.txtDAddress3.TabIndex = 33
        Me.txtDAddress3.Text = ""
        '
        'lblBillingAddress
        '
        Me.lblBillingAddress.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.0!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblBillingAddress.Location = New System.Drawing.Point(280, 112)
        Me.lblBillingAddress.Name = "lblBillingAddress"
        Me.lblBillingAddress.Size = New System.Drawing.Size(120, 23)
        Me.lblBillingAddress.TabIndex = 34
        Me.lblBillingAddress.Text = "Billing Address 4 :"
        '
        'txtDAddress4
        '
        Me.txtDAddress4.Location = New System.Drawing.Point(408, 112)
        Me.txtDAddress4.Name = "txtDAddress4"
        Me.txtDAddress4.TabIndex = 35
        Me.txtDAddress4.Text = ""
        '
        'P
        '
        Me.P.Controls.Add(Me.tabInvoices)
        Me.P.Controls.Add(Me.tabQuotes)
        Me.P.Location = New System.Drawing.Point(16, 360)
        Me.P.Name = "P"
        Me.P.SelectedIndex = 0
        Me.P.Size = New System.Drawing.Size(864, 344)
        Me.P.TabIndex = 36
        '
        'tabInvoices
        '
        Me.tabInvoices.Location = New System.Drawing.Point(4, 22)
        Me.tabInvoices.Name = "tabInvoices"
        Me.tabInvoices.Size = New System.Drawing.Size(856, 318)
        Me.tabInvoices.TabIndex = 0
        Me.tabInvoices.Text = "Invoices"
        '
        'tabQuotes
        '
        Me.tabQuotes.Controls.Add(Me.grdCustomers)
        Me.tabQuotes.Location = New System.Drawing.Point(4, 22)
        Me.tabQuotes.Name = "tabQuotes"
        Me.tabQuotes.Size = New System.Drawing.Size(856, 318)
        Me.tabQuotes.TabIndex = 1
        Me.tabQuotes.Text = "Quotes"
        '
        'btnNewSale
        '
        Me.btnNewSale.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnNewSale.Location = New System.Drawing.Point(888, 120)
        Me.btnNewSale.Name = "btnNewSale"
        Me.btnNewSale.Size = New System.Drawing.Size(120, 23)
        Me.btnNewSale.TabIndex = 37
        Me.btnNewSale.Text = "New Sale"
        '
        'btnQuote
        '
        Me.btnQuote.Font = New System.Drawing.Font("Microsoft Sans Serif", 9.75!, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.btnQuote.Location = New System.Drawing.Point(888, 152)
        Me.btnQuote.Name = "btnQuote"
        Me.btnQuote.Size = New System.Drawing.Size(120, 23)
        Me.btnQuote.TabIndex = 38
        Me.btnQuote.Text = "Create Quote"
        '
        'StatusBar1
        '
        Me.StatusBar1.Location = New System.Drawing.Point(0, 724)
        Me.StatusBar1.Name = "StatusBar1"
        Me.StatusBar1.Size = New System.Drawing.Size(1028, 22)
        Me.StatusBar1.TabIndex = 39
        Me.StatusBar1.Text = "StatusBar1"
        '
        'txtRecordPosition
        '
        Me.txtRecordPosition.Location = New System.Drawing.Point(360, 240)
        Me.txtRecordPosition.Name = "txtRecordPosition"
        Me.txtRecordPosition.Size = New System.Drawing.Size(152, 20)
        Me.txtRecordPosition.TabIndex = 40
        Me.txtRecordPosition.Text = "TextBox1"
        '
        'btnAdd
        '
        Me.btnAdd.Location = New System.Drawing.Point(400, 296)
        Me.btnAdd.Name = "btnAdd"
        Me.btnAdd.Size = New System.Drawing.Size(104, 23)
        Me.btnAdd.TabIndex = 41
        Me.btnAdd.Text = "Add Customer"
        '
        'btnSave
        '
        Me.btnSave.Location = New System.Drawing.Point(512, 296)
        Me.btnSave.Name = "btnSave"
        Me.btnSave.Size = New System.Drawing.Size(104, 23)
        Me.btnSave.TabIndex = 42
        Me.btnSave.Text = "Save Changes"
        '
        'frmCustomers
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(1028, 746)
        Me.Controls.Add(Me.btnSave)
        Me.Controls.Add(Me.btnAdd)
        Me.Controls.Add(Me.txtRecordPosition)
        Me.Controls.Add(Me.StatusBar1)
        Me.Controls.Add(Me.btnQuote)
        Me.Controls.Add(Me.btnNewSale)
        Me.Controls.Add(Me.P)
        Me.Controls.Add(Me.txtDAddress4)
        Me.Controls.Add(Me.lblBillingAddress)
        Me.Controls.Add(Me.txtDAddress3)
        Me.Controls.Add(Me.lblBillingAddress3)
        Me.Controls.Add(Me.txtDAddress2)
        Me.Controls.Add(Me.lblBillingAddress2)
        Me.Controls.Add(Me.txtDAddress1)
        Me.Controls.Add(Me.lblBillingAddress1)
        Me.Controls.Add(Me.txtAddress4)
        Me.Controls.Add(Me.lblAddress4)
        Me.Controls.Add(Me.txtAddress3)
        Me.Controls.Add(Me.lblAddress3)
        Me.Controls.Add(Me.txtAddress2)
        Me.Controls.Add(Me.lblAddress2)
        Me.Controls.Add(Me.txtAddress1)
        Me.Controls.Add(Me.lblAddress1)
        Me.Controls.Add(Me.txtEmailAddress)
        Me.Controls.Add(Me.lblEmailAddress)
        Me.Controls.Add(Me.txtMobNumber)
        Me.Controls.Add(Me.lblMobileNumber)
        Me.Controls.Add(Me.txtFaxNumber)
        Me.Controls.Add(Me.lblFaxNumber)
        Me.Controls.Add(Me.txtContactName)
        Me.Controls.Add(Me.lblCustomerContact)
        Me.Controls.Add(Me.txtPhoneNumber)
        Me.Controls.Add(Me.lblPhoneNumber)
        Me.Controls.Add(Me.btnLast)
        Me.Controls.Add(Me.btnNext)
        Me.Controls.Add(Me.btnPrevious)
        Me.Controls.Add(Me.btn1st)
        Me.Controls.Add(Me.txtCustomerName)
        Me.Controls.Add(Me.lblCustomerName)
        Me.Name = "frmCustomers"
        Me.Text = "Customer Details"
        CType(Me.grdCustomers, System.ComponentModel.ISupportInitialize).EndInit()
        Me.P.ResumeLayout(False)
        Me.tabQuotes.ResumeLayout(False)
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Sub frmCustomers_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.WindowState = FormWindowState.Maximized
        
       
        FillDataSetAndView()
        BindFields()
        ShowPosition()
    End Sub



    Private Sub BindFields()
        txtCustomerName.DataBindings.Add("Text", objDataView, "CustomerName")
        txtContactName.DataBindings.Add("Text", objDataView, "ContactName")
        txtPhoneNumber.DataBindings.Add("Text", objDataView, "PhoneNumber")
        txtFaxNumber.DataBindings.Add("Text", objDataView, "FaxNumber")
        txtMobNumber.DataBindings.Add("Text", objDataView, "MobNumber")
        txtAddress1.DataBindings.Add("Text", objDataView, "Address1")
        txtAddress2.DataBindings.Add("Text", objDataView, "Address2")
        txtAddress3.DataBindings.Add("Text", objDataView, "Address3")
        txtAddress4.DataBindings.Add("Text", objDataView, "Address4")
        txtDAddress1.DataBindings.Add("Text", objDataView, "DAddress1")
        txtDAddress2.DataBindings.Add("Text", objDataView, "DAddress2")
        txtDAddress3.DataBindings.Add("Text", objDataView, "DAddress3")
        txtDAddress4.DataBindings.Add("Text", objDataView, "DAddress4")


        StatusBar1.Text = "Ready"

    End Sub

    Private Sub btn1st_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1st.Click
        objCurrencyManager.Position = 0
        ShowPosition()
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        objCurrencyManager.Position -= 1
        ShowPosition()
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        objCurrencyManager.Position += 1
        ShowPosition()
    End Sub

  
    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        objCurrencyManager.Position = objCurrencyManager.Count - 1
        ShowPosition()
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim intPosition As Integer, intMaxID As Integer
        Dim strID As String
        Dim objCommand As SqlCommand = New SqlCommand
        'Save current record position
        intPosition = objCurrencyManager.Position
        Dim maxIDCommand As SqlCommand = New SqlCommand _
        ("SELECT MAX(CustomerID) as MaxID " & _
        "FROM tblCustomers WHERE customerID LIKE 'DM%'", objConnection)

        objConnection.Open()
        Dim maxID As Object = maxIDCommand.ExecuteScalar()

        ' if the maxid is null...
        If maxID Is DBNull.Value Then
            intMaxID = 1000
        Else
            strID = CType(maxID, String)
            intMaxID = CType(strID.Remove(0, 2), Integer)
            intMaxID += 1

        End If
        strID = "DM" & intMaxID.ToString

        objCommand.Connection = objConnection
        objCommand.CommandText = "INSERT INTO tblCustomers " & _
        "(CustomerName,ContactName " & _
        "VALUES(@CustomerName,@ContactName)"



        objCommand.Parameters.Add("@CustomerName", txtCustomerName.Text)
        objCommand.Parameters.Add("@ContactName", txtContactName.Text)

        'clear()


        ''Excute the INSERT statement
        Try
            objCommand.ExecuteNonQuery()
        Catch SqlExceptionErr As SqlException
            MessageBox.Show(SqlExceptionErr.Message)
        End Try

        objConnection.Close()
        FillDataSetAndView()
        BindFields()
        objCurrencyManager.Position = intPosition
        ShowPosition()
        StatusBar1.Text = "Record added"
        
    End Sub


    Private Sub clear()
        txtCustomerName.Text = ""
        txtContactName.Text = ""
        txtPhoneNumber.Text = ""
        txtFaxNumber.Text = ""
        txtMobNumber.Text = ""
        txtAddress1.Text = ""
        txtAddress2.Text = ""
        txtAddress3.Text = ""
        txtAddress4.Text = ""
        txtDAddress1.Text = ""
        txtDAddress2.Text = ""
        txtDAddress3.Text = ""
        txtDAddress4.Text = ""
    End Sub

    Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        clear()
    End Sub
End Class
Can anyone see what I am doing wrong?
 
Hi

You plz upload the form somewhere and put the link here so that anybody can dowload and fix the errors.. i hope this is not a commercial code.. i think u r just trying to run a sample...

Bye
 
Hi there

I am not 100% sure what I need to attach so people can view so I have added the 2 files that belong to the form.


Any help would be great!!
 

Attachments

  • frmCustomers.zip
    7.2 KB · Views: 44
i need to run ur code in my system to find out what happens.. so send the table's script and insert into statements for sample data..
 
Not sure whether this is your answer but I've literally had the same error on my app;

I'm moving all of my bindings of DataSource, DisplayMember, ValueMember and SelectedValue DataBinding of my combo boxes from setting in the GUI into the code itself.

Where I had left the settings in the GUI as well, I got that error message. Cleared out any databindings, DataSource etc from the combo box and it now works OK.

..just maybe :)

Luke
 
Hi Luke,

I am totally lost on this.

I don't have a dataset setup do I need to?

The form opens up ok and I can select the records that are currently in the database but its when I press a button to add a record back into the database thats when I get the above message.

Why is it that I can see the records in the database but I can't add them. I have followed the book's code and nothing is different!


Thanks for your help.
 
You don't have a dataSet set up but you are creating one in your code...

I read your orginal post wrong, thought you had created the dataAdapters and DataSet in the GUI.

Not sure on the code the book suggests for adding a record. Everything i read to learn always used currency manager and bindings, so that to add a record was as easy as cm.addnew().

Sorry can't be of much help...
 
Hi

sorry for the delayed response, just right click the tables u used in your code in Enterprise Manager and select All Tasks->Generate SQL Script and attach here


bye
 
Thank you

This is my script


VB.NET:
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[FK_tblOrders_tblCustomers]') and OBJECTPROPERTY(id, N'IsForeignKey') = 1)
ALTER TABLE [dbo].[tblOrders] DROP CONSTRAINT FK_tblOrders_tblCustomers
GO
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tblCustomers]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[tblCustomers]
GO
CREATE TABLE [dbo].[tblCustomers] (
 [CustomerID] [int] IDENTITY (1, 1) NOT NULL ,
 [CustomerName] [varchar] (30) COLLATE Latin1_General_CI_AS NOT NULL ,
 [ContactName] [varchar] (30) COLLATE Latin1_General_CI_AS NULL ,
 [PhoneNumber] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [FaxNumber] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [MobNumber] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [EmailAddress] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [Address1] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [Address2] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [Address3] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [Address4] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [DAddress1] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [DAddress2] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [DAddress3] [char] (10) COLLATE Latin1_General_CI_AS NULL ,
 [DAddress4] [char] (10) COLLATE Latin1_General_CI_AS NULL 
) ON [PRIMARY]
GO
Thanks
 
Fixed

Two things i noticed which should have caused the problem..

One...
VB.NET:
txtCustomerName.DataBindings.Add("Text", objDataView, "CustomerName")
the above code caused the error "This would cause two bindings in the collection to bind to the same property."

which means you cannot add bindings for a same property more than once

this function is being called after Add button's click which was already called in form load also...

so to fix this..
just change the code like this for all the textboxes..
VB.NET:
txtCustomerName.DataBindings.Clear ' this clears all the databindings of txtCustomerName control
txtCustomerName.DataBindings.Add("Text", objDataView, "CustomerName")


second..
VB.NET:
objCommand.CommandText = "INSERT INTO tblCustomers " & _
"(CustomerName,ContactName " & _
"VALUES(@CustomerName,@ContactName)"

U have missed a ")"- closing bracket before the VALUES keyword, but u didnt mentioned this in your post, so u should have mistyped or pasted it wrongly while posting the code..


I think this should help u..

Bye
 

Latest posts

Back
Top