|
-
Feb 25th, 2009, 03:31 PM
#1
Thread Starter
Addicted Member
[2008] DataGridView Question - Inserting New records to database conditionally
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
-
Mar 2nd, 2009, 12:22 PM
#2
Thread Starter
Addicted Member
Re: [2008] DataGridView Question - Inserting New records to database conditionally
still having this issue. Any ideas?
-
Mar 4th, 2009, 09:59 AM
#3
Thread Starter
Addicted Member
Re: [2008] DataGridView Question - Inserting New records to database conditionally
can just a simple If statement resolve this? I have tried it to no avail.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|