Can someone tell me what I am missing... I am not getting any errors returned but No data is being populated within the database?????
Any Help would be very much appricated!!!!
Dim myCommand As SqlCommand
Dim myConnection As SqlConnection
Dim insertCmd As String
myConnection = New SqlConnection("Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|CustomerInfo.mdf;Integrated Security=True;User Instance=True")
insertCmd = "Insert into CustomerTable Values (@WorkSheetID, @Origin, @DealerName, @DateCreated, " _
& "@SalesRep, @BkupSalesRep, @FirstName, @MiddleName, @LastName, @Address, @City, @State, " _
& "@Zip, @HomePhone, @WorkPhone, @CellPhone, @Email, @County, @SalesTax, @SS, @DOB)"
myCommand = New SqlCommand(insertCmd, myConnection)
myCommand.Parameters.Add(New SqlParameter("@WorkSheetID", Data.SqlDbType.NVarChar))
myCommand.Parameters("@WorkSheetID").Value = lblCustWksnum.Text
myCommand.Parameters.Add(New SqlParameter("@Origin", Data.SqlDbType.NVarChar))
myCommand.Parameters("@Origin").Value = lblSaleOrigin.Text
myCommand.Parameters.Add(New SqlParameter("@DealerName", Data.SqlDbType.Char))
myCommand.Parameters("@DealerName").Value = lblDealerShipName.Text
myCommand.Parameters.Add(New SqlParameter("@DateCreated", Data.SqlDbType.NVarChar))
myCommand.Parameters("@DateCreated").Value = lblDateCreated.Text
myCommand.Parameters.Add(New SqlParameter("@SalesRep", Data.SqlDbType.NVarChar))
myCommand.Parameters("@SalesRep").Value = lblSlsRep.Text
myCommand.Parameters.Add(New SqlParameter("@BkupSalesRep", Data.SqlDbType.NVarChar))
myCommand.Parameters("@BkupSalesRep").Value = lblBkupSlsRep.Text
myCommand.Parameters.Add(New SqlParameter("@FirstName", Data.SqlDbType.NVarChar))
myCommand.Parameters("@FirstName").Value = lblcFirstName.Text
myCommand.Parameters.Add(New SqlParameter("@MiddleName", Data.SqlDbType.NVarChar))
myCommand.Parameters("@MiddleName").Value = lblcMiddleName.Text
myCommand.Parameters.Add(New SqlParameter("@LastName", Data.SqlDbType.NVarChar))
myCommand.Parameters("@LastName").Value = lblcLastName.Text
myCommand.Parameters.Add(New SqlParameter("@Address", Data.SqlDbType.NVarChar))
myCommand.Parameters("@Address").Value = rBuyAddress
myCommand.Parameters.Add(New SqlParameter("@City", Data.SqlDbType.NVarChar))
myCommand.Parameters("@City").Value = rcity
myCommand.Parameters.Add(New SqlParameter("@State", Data.SqlDbType.NVarChar))
myCommand.Parameters("@State").Value = rState
myCommand.Parameters.Add(New SqlParameter("@Zip", Data.SqlDbType.NVarChar))
myCommand.Parameters("@Zip").Value = rZip
myCommand.Parameters.Add(New SqlParameter("@HomePhone", Data.SqlDbType.NVarChar))
myCommand.Parameters("@HomePhone").Value = lblHnum.Text
myCommand.Parameters.Add(New SqlParameter("@WorkPhone", Data.SqlDbType.NVarChar))
myCommand.Parameters("@WorkPhone").Value = lblWnum.Text
myCommand.Parameters.Add(New SqlParameter("@CellPhone", Data.SqlDbType.NVarChar))
myCommand.Parameters("@CellPhone").Value = lblCnum.Text
myCommand.Parameters.Add(New SqlParameter("@Email", Data.SqlDbType.NVarChar))
myCommand.Parameters("@Email").Value = lblEmailAddres.Text
myCommand.Parameters.Add(New SqlParameter("@County", Data.SqlDbType.NVarChar))
myCommand.Parameters("@County").Value = lblBuyersCounty.Text
myCommand.Parameters.Add(New SqlParameter("@SalesTax", Data.SqlDbType.NVarChar))
myCommand.Parameters("@SalesTax").Value = lblSalesTax.Text
myCommand.Parameters.Add(New SqlParameter("@SS", Data.SqlDbType.NVarChar))
myCommand.Parameters("@SS").Value = lblSSN.Text
myCommand.Parameters.Add(New SqlParameter("@DOB", Data.SqlDbType.NVarChar))
myCommand.Parameters("@DOB").Value = lblDOB.Text
myCommand.Connection.Open()
Try
myCommand.ExecuteNonQuery()
ShowMessageBox(Me, "Record Added " & insertCmd)
Catch ex As SqlException
If ex.Number = 2627 Then
ShowMessageBox(Me, "ERROR: A record already exists with " _
& "the same primary key")
Else
ShowMessageBox(Me, "ERROR: Could not add record")
End If
End Try
myCommand.Connection.Close()
Any Help would be very much appricated!!!!
Dim myCommand As SqlCommand
Dim myConnection As SqlConnection
Dim insertCmd As String
myConnection = New SqlConnection("Server=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|CustomerInfo.mdf;Integrated Security=True;User Instance=True")
insertCmd = "Insert into CustomerTable Values (@WorkSheetID, @Origin, @DealerName, @DateCreated, " _
& "@SalesRep, @BkupSalesRep, @FirstName, @MiddleName, @LastName, @Address, @City, @State, " _
& "@Zip, @HomePhone, @WorkPhone, @CellPhone, @Email, @County, @SalesTax, @SS, @DOB)"
myCommand = New SqlCommand(insertCmd, myConnection)
myCommand.Parameters.Add(New SqlParameter("@WorkSheetID", Data.SqlDbType.NVarChar))
myCommand.Parameters("@WorkSheetID").Value = lblCustWksnum.Text
myCommand.Parameters.Add(New SqlParameter("@Origin", Data.SqlDbType.NVarChar))
myCommand.Parameters("@Origin").Value = lblSaleOrigin.Text
myCommand.Parameters.Add(New SqlParameter("@DealerName", Data.SqlDbType.Char))
myCommand.Parameters("@DealerName").Value = lblDealerShipName.Text
myCommand.Parameters.Add(New SqlParameter("@DateCreated", Data.SqlDbType.NVarChar))
myCommand.Parameters("@DateCreated").Value = lblDateCreated.Text
myCommand.Parameters.Add(New SqlParameter("@SalesRep", Data.SqlDbType.NVarChar))
myCommand.Parameters("@SalesRep").Value = lblSlsRep.Text
myCommand.Parameters.Add(New SqlParameter("@BkupSalesRep", Data.SqlDbType.NVarChar))
myCommand.Parameters("@BkupSalesRep").Value = lblBkupSlsRep.Text
myCommand.Parameters.Add(New SqlParameter("@FirstName", Data.SqlDbType.NVarChar))
myCommand.Parameters("@FirstName").Value = lblcFirstName.Text
myCommand.Parameters.Add(New SqlParameter("@MiddleName", Data.SqlDbType.NVarChar))
myCommand.Parameters("@MiddleName").Value = lblcMiddleName.Text
myCommand.Parameters.Add(New SqlParameter("@LastName", Data.SqlDbType.NVarChar))
myCommand.Parameters("@LastName").Value = lblcLastName.Text
myCommand.Parameters.Add(New SqlParameter("@Address", Data.SqlDbType.NVarChar))
myCommand.Parameters("@Address").Value = rBuyAddress
myCommand.Parameters.Add(New SqlParameter("@City", Data.SqlDbType.NVarChar))
myCommand.Parameters("@City").Value = rcity
myCommand.Parameters.Add(New SqlParameter("@State", Data.SqlDbType.NVarChar))
myCommand.Parameters("@State").Value = rState
myCommand.Parameters.Add(New SqlParameter("@Zip", Data.SqlDbType.NVarChar))
myCommand.Parameters("@Zip").Value = rZip
myCommand.Parameters.Add(New SqlParameter("@HomePhone", Data.SqlDbType.NVarChar))
myCommand.Parameters("@HomePhone").Value = lblHnum.Text
myCommand.Parameters.Add(New SqlParameter("@WorkPhone", Data.SqlDbType.NVarChar))
myCommand.Parameters("@WorkPhone").Value = lblWnum.Text
myCommand.Parameters.Add(New SqlParameter("@CellPhone", Data.SqlDbType.NVarChar))
myCommand.Parameters("@CellPhone").Value = lblCnum.Text
myCommand.Parameters.Add(New SqlParameter("@Email", Data.SqlDbType.NVarChar))
myCommand.Parameters("@Email").Value = lblEmailAddres.Text
myCommand.Parameters.Add(New SqlParameter("@County", Data.SqlDbType.NVarChar))
myCommand.Parameters("@County").Value = lblBuyersCounty.Text
myCommand.Parameters.Add(New SqlParameter("@SalesTax", Data.SqlDbType.NVarChar))
myCommand.Parameters("@SalesTax").Value = lblSalesTax.Text
myCommand.Parameters.Add(New SqlParameter("@SS", Data.SqlDbType.NVarChar))
myCommand.Parameters("@SS").Value = lblSSN.Text
myCommand.Parameters.Add(New SqlParameter("@DOB", Data.SqlDbType.NVarChar))
myCommand.Parameters("@DOB").Value = lblDOB.Text
myCommand.Connection.Open()
Try
myCommand.ExecuteNonQuery()
ShowMessageBox(Me, "Record Added " & insertCmd)
Catch ex As SqlException
If ex.Number = 2627 Then
ShowMessageBox(Me, "ERROR: A record already exists with " _
& "the same primary key")
Else
ShowMessageBox(Me, "ERROR: Could not add record")
End If
End Try
myCommand.Connection.Close()