大佬教程收集整理的这篇文章主要介绍了vb.net 教程 8-3 数据库操作10-2,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
接上一节,下面开始正式进行修改:
Private Sub btnEdit1_Click(sender As Object,e As EventArgs) Handles btnEdit1.Click Dim id As @R_607_8056@r = cbemployee.SELEctedIndex + 1 Dim odcommand As New OleDbCommand() odcommand.CommandText = "@R_674_9531@e 雇员 set 职务='" & txtDuties.Text & "',尊称='" & txtAppellation.Text & "',出生日期='" & dtpBirthday.Value & "',雇用日期='" & dtpemployDay.Value & "',国家='" & txtCountry.Text & "',城市='" & txtCity.Text & "',地区='" & txtArea.Text & "',地址='" & txtAddress.Text & "',邮政编码='" & txtZipcode.Text & "',家庭电话='" & txtPhone.Text & "' where 雇员ID=" & id odcommand.Connection = odc Dim @R_674_9531@eCount As @R_607_8056@r Try @R_674_9531@eCount = odcommand.ExecuteNonQuery() messageBox.Show("修改成功 " & @R_674_9531@eCount & " 条") Catch ex As Exception messageBox.Show("修改失败:" & ex.messagE) End Try End Sub
odcommand.ExecuteNonQuery返回修改的条数。
也可以用加参数的方法:
Private Sub btnEdit2_Click(sender As Object,e As EventArgs) Handles btnEdit2.Click Dim id As @R_607_8056@r = cbemployee.SELEctedIndex + 1 Dim odcommand As New OleDbCommand() odcommand.CommandText = "@R_674_9531@e 雇员 set 职务=@Duties,尊称=@Appellation,出生日期=@Birthday,雇用日期=@employDay,国家=@Country,城市=@City,地区=@Area,地址=@Address,邮政编码=@Zipcode,家庭电话=@phone where 雇员ID=" & id odcommand.Connection = odc odcommand.Parameters.Add("@Duties",OleDbType.VarChar) odcommand.Parameters("@Duties").Value = txtDuties.Text odcommand.Parameters.Add("@Appellation",OleDbType.VarChar) odcommand.Parameters("@Appellation").Value = txtAppellation.Text odcommand.Parameters.Add("@Birthday",OleDbType.DatE) odcommand.Parameters("@Birthday").Value = dtpBirthday.Value odcommand.Parameters.Add("@employDay",OleDbType.DatE) odcommand.Parameters("@employDay").Value = dtpemployDay.Value odcommand.Parameters.Add("@Country",OleDbType.VarChar) odcommand.Parameters("@Country").Value = txtCountry.Text odcommand.Parameters.Add("@City",OleDbType.VarChar) odcommand.Parameters("@City").Value = txtCity.Text odcommand.Parameters.Add("@Area",OleDbType.VarChar) odcommand.Parameters("@Area").Value = txtArea.Text odcommand.Parameters.Add("@Address",OleDbType.VarChar) odcommand.Parameters("@Address").Value = txtAddress.Text odcommand.Parameters.Add("@Zipcode",OleDbType.VarChar) odcommand.Parameters("@Zipcode").Value = txtZipcode.Text odcommand.Parameters.Add("@phone",OleDbType.VarChar) odcommand.Parameters("@phone").Value = txtPhone.Text Dim @R_674_9531@eCount As @R_607_8056@r Try @R_674_9531@eCount = odcommand.ExecuteNonQuery() messageBox.Show("修改成功 " & @R_674_9531@eCount & " 条") Catch ex As Exception messageBox.Show("修改失败:" & ex.messagE) End Try End Sub
两种方法都可以使用。
最后别忘了窗体关闭的时候,关闭数据库连接:
Private Sub Form6_Closing(sender As Object,e As CancelEventArgs) Handles Me.Closing odc.Close() End Sub
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看vb.net 教程 目录
@H_197_21@以上是大佬教程为你收集整理的vb.net 教程 8-3 数据库操作10-2全部内容,希望文章能够帮你解决vb.net 教程 8-3 数据库操作10-2所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。