使用sql插入行,具体取决于listbox是否为空

时间:2018-05-07 00:07:40

标签: c#

如果列表框中没有其他项目,并且用户点击了下一个'按钮,我希望系统在数据库中插入一行...但数据库中没有任何内容。有人可以帮忙吗?

Sub ReplaceComments()
Dim cmt As Comment
Dim wks As Worksheet
Dim sFind As String
Dim sReplace As String
Dim sCmt As String
sFind = "2011"
sReplace = "2012"
For Each wks In ActiveWorkbook.Worksheets
For Each cmt In wks.Comments
sCmt = cmt.Text
If InStr(sCmt, sFind) <> 0 Then
sCmt = Application.WorksheetFunction. _
Substitute(sCmt, sFind, sReplace)
cmt.Text Text:=sCmt
End If
Next
Next
Set wks = Nothing
Set cmt = Nothing
End Sub

1 个答案:

答案 0 :(得分:0)

你必须使用:

SqlCommand cmd = new SqlCommand Instead of 

OleDbCommand cmd = new OleDbCommand

SqlConnection

相同

所有OleDb更改为Sql;

确保connection string用于SQL Server;