gpt4 book ai didi

database - 更新datagridview和数据库vb.net

转载 作者:搜寻专家 更新时间:2023-10-30 19:54:12 24 4
gpt4 key购买 nike

我想更新我的 datagridview 和我的数据库,我是 vb 的新手,我不知道我做错了什么有人可以帮助我吗?

Private Sub DataGridView_Booking_Update(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView_Booking.RowLeave
Try
con.Open()
Using cmd As New SqlCommand("UPDATE Tbl_booking SET Omschrijving = @Omschrijving, Jaar = @Jaar, Opmerking = @Opmerking ,Sortnr = @Sortnr)", con)
cmd.Parameters.Add("@Omschrijving", SqlDbType.VarChar)
cmd.Parameters.Add("@Jaar", SqlDbType.Int)
cmd.Parameters.Add("@Opmerking", SqlDbType.VarChar)
cmd.Parameters.Add("@Sortnr", SqlDbType.Int)
cmd.ExecuteNonQuery()

End Using
Catch ex As Exception
MessageBox.Show("Error while updating record on table..." & ex.Message, "Update Records")
Finally
con.Close()
End Try

最佳答案

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Try
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\database1.accdb;Persist Security Info=False;")
con.Open()
Dim cmd As New OleDb.OleDbCommand("INSERT INTO table1(name,age,class) VALUES('John Legend','22','B.A Part 1')", con)
cmd.ExecuteNonQuery()
MsgBox("Record inserted successfully.")
con.Close()
Catch
MsgBox("Error Occured.")
End Try
End Sub

Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Try
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\database1.accdb;Persist Security Info=False;")
con.Open()
Dim cmd As New OleDb.OleDbCommand("update table1 set name='John DOE',age='23',class='12th' where id='1'", con)
cmd.ExecuteNonQuery()
MsgBox("Record Updated Successfully.")
con.Close()
Catch
MsgBox("Error Occured.")
End Try
End Sub

Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
Try
Dim con As New OleDb.OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\database1.accdb;Persist Security Info=False;")
con.Open()
Dim cmd As New OleDb.OleDbCommand("Delete from table1 where name='John DOE'", con)
cmd.ExecuteNonQuery()
MsgBox("Record Deleted Successfully.")
con.Close()
Catch
MsgBox("Error Occured.")
End Try
End Sub

Private Sub DataGridView1_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles DataGridView1.CellValueChanged

Me.Validate()
Me.dbDataAdapter.Update(Me.dbdataset.Tables("MyTable"))

Me.dbDataSet.AcceptChanges()

End Sub

关于database - 更新datagridview和数据库vb.net,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39593371/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com