Insert new records only into SQL Table Using VBA

前端 未结 3 481
小鲜肉
小鲜肉 2020-12-29 12:40

I have an Excel workbook with the below code -

Sub Button1_Click()
    Dim conn As New ADODB.Connection
    Dim iRowNo         


        
3条回答
  •  长发绾君心
    2020-12-29 13:02

    You can use sql query like this:

    IF Exists ( Select 1 from dbo.customers where Firstname = '" & sFirstName & "' and LastName = '" & sLastName & "' THEN Update dbo.customers set --other columns where Firstname = '" & sFirstName & "' and LastName = '" & sLastName & "'
    ELSE Insert into dbo.Customers (FirstName, LastName) " & _
                         "values ('" & sFirstName & "', '" & sLastName & "')"
    

    Not sure about the syntax for excel and C#, you can correct that similar to this query

提交回复
热议问题