purplehaze1
Programmer
I can't get commandbuilder to generate insert/update/delete command in Sybase, so I want to write my own update logic. But I want to avoid writing update/insert/delete routine for each table. I've got about 40 tables. Is there a way for doing this?
Thanx.
Public function SaveCustomer() as boolean
Dim strsql As String
Dim myCommand As OdbcCommand
Dim dr As DataRow
Try
strsql = "SELECT * FROM t_customer WHERE cust_id=" & m_custID
myCommand = New OdbcCommand(strsql, myConnection)
Dim da As New OdbcDataAdapter(myCommand)
Dim ds As New DataSet()
da.Fill(ds, "Customer")
If ds.Tables(0).Rows.Count = 0 Then
dr = ds.Tables(0).NewRow()
IsNew = True
GoTo SaveRecord
Else
dr = ds.Tables(0).Rows(0)
End If
SaveRecord:
dr("Address") = IIF(m_address = String.Empty, String.Empty, m_address)
dr("BillingRate") = m_billingrate
...etc
If ds.Tables(0).Rows.Count = 0 Then
InsertRecord(dr)
Else
UpdateRecord(dr)
End If
End Function
----------------------------
Insert/Update/Delete Functions
----------------------------
Public Sub InsertRecord(ByVal dr as DataRow)
Dim strSQL as String
strSQL = "INSERT INTO Employees "
strSQL &= "(Address, "
strSQL &= "BillingRate)"
strSQL &= "VALUES ("
strSQL &= dr("Address") ","
strSQL &= dr("BillingRate") ");"
dbCmd.CommandText = strSQL
Try
dbConn.Open()
dbCmd.ExecuteNonQuery()
Finally
dbConn.Close()
End Try
End Sub
...Same for update & Delete