本文介绍了在代码中更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 我一直在尝试更新我编辑的记录,似乎无法想象我错过了什么。这是我必须在 格式上加载记录的代码: '' ***** ********************************************* ***** ********************* ***************** Private Sub ContactMain_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)处理MyBase.Load Dim strSQL As String strSQL =" Select * from Contact WHERE sysID =''" &安培; g_sysID& "''" objDS.Clear() Dim cmb As SqlClient.SqlCommandBuilder = New SqlClient.SqlCommandBuilder (DA) Dim selectCommand As New SqlClient.SqlCommand(strSQL) DA.SelectCommand = selectCommand DA.SelectCommand.Connection = CN DA.Fill(objDS,联系人) Me.txtFirstName.DataBindings.Add(" Text",objDS, " Contact.first_name") Me.txtLastName.DataBindings.Add(" Text",objDS," Contact.Last_name") Me.txtFullName.DataBindings.Add(" Text",objDS," Contact.full_name") Me.txtAddress1.DataBindings.Add(" Text",objDS," Contact .con1_02_03") Me.txtPhone.DataBindings.Add(" Text",objDS," Contact.Phone1") Me.txtCity.DataBindings.Add( " Text",objDS," Contact.con1_02_05") Me.txtState.DataBindings.A dd(" Text",objDS," Contact.con1_02_06") Me.txtZip.DataBindings.Add(" Text",objDS," Contact.con1_02_07") Me.txtEMail.DataBindings.Add(" Text",objDS," Contact.con1_03_01") End Sub 以下是更新的代码: '' ***************** ********************************* ***************** ********* ***************** Private Sub btnSave_Click(ByVal sender As System .Object,ByVal e As System.EventArgs)处理btnSave.Click 尝试 DirectCast(BindingContext(objDS.Tables) (0)), CurrencyManager)。EndCurrentEdit() Me.Close() Catch ex As Exception MsgBox(ex.Message) 结束尝试 结束子 我缺少什么?我是否需要对INSERT,UPDATE和DELETE命令进行编码 如果是这样,我在哪里放置它们?我有九个领域,我正在与之合作 请帮我更新我的记录。任何代码示例都将不胜感激。 谢谢, Gary 解决方案 I have been trying to update a record that I edited and can''t seem to figureout what I''m missing. Here is the code that I have to load the record onthe form: ''************************************************** *******************************************Private Sub ContactMain_Load(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles MyBase.Load Dim strSQL As String strSQL = "Select * from Contact WHERE sysID = ''" & g_sysID & "''"objDS.Clear() Dim cmb As SqlClient.SqlCommandBuilder = NewSqlClient.SqlCommandBuilder(DA)Dim selectCommand As New SqlClient.SqlCommand(strSQL)DA.SelectCommand = selectCommandDA.SelectCommand.Connection = CN DA.Fill(objDS, "Contact") Me.txtFirstName.DataBindings.Add("Text", objDS,"Contact.first_name")Me.txtLastName.DataBindings.Add("Text", objDS, "Contact.Last_name")Me.txtFullName.DataBindings.Add("Text", objDS, "Contact.full_name")Me.txtAddress1.DataBindings.Add("Text", objDS, "Contact.con1_02_03")Me.txtPhone.DataBindings.Add("Text", objDS, "Contact.Phone1")Me.txtCity.DataBindings.Add("Text", objDS, "Contact.con1_02_05")Me.txtState.DataBindings.Add("Text", objDS, "Contact.con1_02_06")Me.txtZip.DataBindings.Add("Text", objDS, "Contact.con1_02_07")Me.txtEMail.DataBindings.Add("Text", objDS, "Contact.con1_03_01") End Sub And here is the code for the update: ''************************************************** *******************************************Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e AsSystem.EventArgs) Handles btnSave.Click TryDirectCast(BindingContext(objDS.Tables(0)),CurrencyManager).EndCurrentEdit()Me.Close() Catch ex As Exception MsgBox(ex.Message) End Try End SubWhat am I missing? Do I need to code the INSERT, UPDATE, and DELETE commandand if so, where do I put them? I have nine fields that I''m working with soplease help me update my record. Any code examples would be appreciated. Thanks, Gary 解决方案 这篇关于在代码中更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 11-03 13:56