Insert Where Value不为null

时间:2018-03-23 07:47:18

标签: sql excel vba excel-vba

我的Excel VBA上有以下代码:

Sub Button3_Click()
Dim conn As New ADODB.Connection

With Sheets("Sheet1")
    conn.Open "Provider=SQLNCLI11;Server=myServer;Database=myDatabase;Trusted_Connection=yes;"

    iRowNo = 6

    Do Until .Cells(iRowNo, 1) = ""
        dtDateTime = .Cells(iRowNo, 1)
        sTag = .Cells(iRowNo, 10)
        conn.Execute "insert into RawData(oDateTime,oTag) values ('" & dtDateTime & "', '" & sTag & "')"

        iRowNo = iRowNo + 1
        Application.StatusBar = "Processing..."
    Loop
    MsgBox "Upload success!", vbInformation, "AOA"

    Sheet1.Range("A6", "L100000").ClearContents
    Sheet1.Cells(6, 1).Select

    conn.Close
    Set conn = Nothing
End With
End Sub

如果您检查上面的代码,则有两个值要添加到表中。当sTag单元格为空时,是否可以跳过记录? 如果sTag单元格为null,则插入下一条记录。这样的事情。

请帮助。
谢谢。

2 个答案:

答案 0 :(得分:4)

您可以有条件地执行插入操作,即在If语句中执行insert insert命令执行,在此语句中检查sTag是否为空。

If sTag <> "" Then
    conn.Execute "insert into RawData(oDateTime,oTag) values ('" & dtDateTime & "', '" & sTag & "')"
End If

答案 1 :(得分:1)

尝试:

<html>

<body>
<input id = "text1" type ="text"/>
</body>

<script>
function dumpCSSText(element){
  var s = '';
  var o = window.getComputedStyle(element);
  for(var i = 0; i < o.length; i++){
    s+=o[i] + ':' + o.getPropertyValue(o[i])+';';
  }
  return s;
}
console.log(dumpCSSText(document.getElementById("text1")));
</script>
</html>