On the main form of my app, I have a binding navigator that will navigate between records stored in the main table of the database. There is also a button on the form that can be clicked that inserts some data into a new table dependent on the ksID that is active on the form. Here is the code I have for that button now.
Is this the right idea? Also, if this button is clicked a 2nd time after a record is saved, I don't want it to insert a new record since one already exists. How would this be accomplished?
Code:Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click connetionString = "Data Source=HERCULES;Initial Catalog=Carc2;Integrated Security=True" sql = "SELECT * FROM t_resales" connection = New SqlConnection(connetionString) Try connection.Open() command = New SqlCommand(sql, connection) adapter.SelectCommand = command adapter.Fill(ds1, "Add New") adapter.Dispose() command.Dispose() connection.Close() dv = New DataView(ds1.Tables(0)) Dim newRow As DataRowView = dv.AddNew() newRow("ksId") = txtKsId.Text newRow("Quantity") = txtResales.Text newRow("Weight") = txtResalesWeight.Text newRow("PaidAmount") = txtResalePay.Text 'newRow("Reason") = "test" newRow.EndEdit() 'dv.Sort = "product_id" frmResales.dgvResales.DataSource = dv Catch ex As Exception MsgBox(ex.ToString) End Try frmResales.ShowDialog() End Sub




Reply With Quote