I am studying vb.net and am trying to develop a data access program
I am getting the following error when I try to add a new record to the dataset. Any help would be great

error " Input string was not in correct format. Could not store<LinenIndex> in LinenItemsID colomn expected type is int32"

On the sql database both tables column are set to int but I don't know how to pass the value member as as int32 at runtime

Thanks

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim ds As New DataSet
        Dim Dalin As New SqlDataAdapter("Select * From TblLinen", Con)

        Dalin.Fill(ds, "TblLinen")

        Try
            Dim NewRow As DataRow
            NewRow = ds.Tables("TblLinen").NewRow
            NewRow("CustomerID") = Me.cboCustomer.ValueMember
            NewRow("LinenItemsID") = Me.cboItems.ValueMember
            NewRow("Quantity") = Me.txtQuantity.Text
           
            ds.Tables("TblLinen").Rows.Add(NewRow)
        Catch ex As Exception
            MessageBox.Show("Message" & ex.ToString & "Failed to add new row to DataTable ")
        End Try
    End Sub

Recommended Answers

All 3 Replies

if its the selected value tht u want to add
then try

cbocustomer.selecteditem.tostring

Type mismatch error - Input string was not in correct format
You are assigning a valueMember property (string - name of column) to int type column.

Try
            Dim NewRow As DataRow
            NewRow = ds.Tables("TblLinen").NewRow
            NewRow("CustomerID") = Me.cboCustomer.SelectedValue
            NewRow("LinenItemsID") = Me.cboItems.SelectedValue
            NewRow("Quantity") = Me.txtQuantity.Text
           
            ds.Tables("TblLinen").Rows.Add(NewRow)
        Catch ex As Exception
            MessageBox.Show("Message" & ex.ToString & "Failed to add new row to DataTable ")
        End Try

Thank you adatapost and babbu ,It solved the problem that I have been stuck on for weeks!!!! just needed then to add a sqlcommandbuilder and all works fine now

Thanks again

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.