使用insert编辑列中的数据?

时间:2011-08-21 07:50:15

标签: mysql sql vb.net

我正在尝试编辑列的数据。我在文本框中加载列,让用户编辑字段。但是现在要插入它,我知道我可以删除该列并添加一个新列,但是我不能只覆盖列中的数据吗?

谢谢!

'Edit Customer
Dim bllKlant As New bllKlant
Dim objKlant As New Klant
objKlant.KlantNaam = txtNaam.Text
objKlant.KlantBtwNr = txtBtw.Text
objKlant.KlantCode = txtCode.Text
objKlant.KlantAdminLidID = ddlLeden.SelectedValue
objKlant.KlantDealerID = ddlDealers.SelectedValue

'Edit+ checks
bllKlant.bewerkKlant(objKlant)

在bllKlant中,我调用函数来插入/更新列。

在dalKlant中我使用该函数并返回一个布尔值,无论更新是否成功。 Klant =客户,它只是在荷兰。

1 个答案:

答案 0 :(得分:2)

好的,这就是我解决它的方法。

在aspx.vb页面中,我做了以下

Dim bllCust As New bllCust
Dim objCust As New Cust
objCust.Custname = txtName.Text
objCust.CustBtwNr = txtBtw.Text
objCust.CustCode = txtCode.Text
objCust.CustAdminUserID = ddlUsers.SelectedValue
objCust.CustDealerID = ddlDealers.SelectedValue

'Edit+ checks
Try
   bllCust.EditCust(objCust)
Catch ex As Exception
   lblFeedback.Text = ex.Message
End Try

在bllCust中:

Public Function EditCust(ByVal objCust As Cust) As Boolean
<!-- I have checks here to see whether the values don't already excist. -->

    If dataKlant.EditCust(objCust) Then
        Throw New Exception("Customer was edited.")
        Return True
    Else
        Throw New Exception("Customer couldn't be edited, try again.")
        Return False
    End If
End Function

然后终于在dalCust:

Public Function EditCust(ByVal objCust As Cust) As Boolean
    myconn.Open()

    Dim result As New Boolean

    Dim SQL As String = "update Cust set CustName= @CustName, CustCode = @CustCode where CustID= @CustID"
    Dim cmd As New MySqlCommand(SQL, myconn)

    cmd.Parameters.AddWithValue("@CustID", objCust.CustID)
    cmd.Parameters.AddWithValue("@CustName", objCust.CustName)
    cmd.Parameters.AddWithValue("@CustCode", objCust.CustCode)

    result= cmd.ExecuteNonQuery()

    myconn.Close()
    Return result
End Function

我就是这样做的。我还把荷兰语翻译成英语,这样每个人都能更好地理解它。