here's my scenario, i have 2 listboxes and 2 buttons (add and remove) and its works as follow:
my first listbox (listbox1) contains all my items and my second listbox (accessorieslistbox) get items from the first listbox when the add button is cliked (the user select as many item as he/she want then add them in the second listbox)and the remove button does the inverse
and then after selecting all the needed items the user click on the bindingnsvigatorsaveitem to save all the item into my table
Here's what i have:
Private Sub Unit_OrderBindingNavigatorSaveItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Unit_OrderBindingNavigatorSaveItem.Click
Dim conn As New SqlClient.SqlConnection(My.Settings.NewEvapcoDBConnectionString.ToString)
Dim j As Integer = Me.AccessoriesListBox.Items.Count
Try
conn.Open()
BindingNavigatorAddNewItem.Visible = True
If UnitSerialNumberTextBox.Text = "" Then
' Throw New Global.System.ArgumentNullException("UnitSerialNumber")
MessageBox.Show("Enter the Unit Serial Number ", "Unit Order")
Else
Me.Validate()
Me.Unit_OrderBindingSource.EndEdit()
Me.Unit_OrderTableAdapter.Update(Me.UnitOrderDataSet.Unit_Order)
For i As Integer = 0 To j - 1
Dim sqlcmd As String = ("INSERT INTO Unit Order(Accessories) values (" & Me.AccessoriesListBox.Items(i) & " ',' ")
Dim cmd As New SqlClient.SqlCommand(sqlcmd, conn)
cmd.ExecuteNonQuery()
Next
MessageBox.Show("Update Successful", "Unit Order")
Me.BindingNavigatorAddNewItem.Visible = True
Me.BindingNavigatorDeleteItem.Visible = True
End If
Catch ex As System.Exception
MsgBox("An error Occured while saving", vbCritical, "Error")
End Try
End Sub
now when i am saving its just saying my exception message :"An Error Occured while saving"
can anyone help me to solve this?please

New Topic/Question
Reply



MultiQuote




|