我有一个插入SQL语句包含在一个stringbuilder中。如果col2变量包含NULL值,我想删除col2的两行。这将允许我插入一个NULL值到col2StringBuilder删除行
这是我的代码。
Private Sub insertStmt(ByVal col2 As Integer)
If IsDBNull(col2) Then
'Remove line 'Col2'
End If
Dim sb As StringBuilder = New StringBuilder
sb.Append("INSERT INTO TABLE")
sb.Append("(")
sb.Append("Col1,")
sb.Append("Col2,")
sb.Append("Col3,")
sb.Append("Col4")
sb.Append(")")
sb.Append("VALUES")
sb.Append("(")
sb.Append("1,")
sb.Append(" " & col2 & ", ")
sb.Append("'abc',")
sb.Append("'xyz'")
sb.Append(")")
End Sub
这是一个不好的创建SQL的方法,因为它不能防范SQL注入攻击和其他各种事情。使用SQL参数 – Plutonix