C# 将内联查询转换为存储过程
我有一个vb.net代码,内联查询如下。我需要将内联查询转换为存储过程C# 将内联查询转换为存储过程,c#,sql,vb.net,C#,Sql,Vb.net,我有一个vb.net代码,内联查询如下。我需要将内联查询转换为存储过程 If Not chkShowAll.Checked Then For Each _row As DataGridViewRow In dgInvestor.Rows If ValidateDate(_row.Cells(2).Value.ToString, _Date) Then sSQL = "INSERT INTO INVESTOR_ACCOUNT VALUES('" &
If Not chkShowAll.Checked Then
For Each _row As DataGridViewRow In dgInvestor.Rows
If ValidateDate(_row.Cells(2).Value.ToString, _Date) Then
sSQL = "INSERT INTO INVESTOR_ACCOUNT VALUES('" & _row.Cells(0).Value & "'," & _row.Cells(1).Value & "," & _Date & ")"
_Dta.RunQuery(cn, sSQL)
End If
Next
End IF
在这种情况下,将为每一行执行存储过程,这将导致性能问题
请给我建议一些避免多次调用存储过程的解决方案
If Not chkShowAll.Checked Then
For Each _row As DataGridViewRow In dgInvestor.Rows
If ValidateDate(_row.Cells(2).Value.ToString, _Date) Then
sSQL = "INSERT INTO INVESTOR_ACCOUNT VALUES('" & _row.Cells(0).Value & "'," & _row.Cells(1).Value & "," & _Date & ")"
_Dta.RunQuery(cn, sSQL)
End If
Next
End IF
如果您使用的是SQL Server 2008及更高版本,则可以使用表值参数一次将所有行传递到SP。请参阅文章,或者您可以将xml作为参数传递给SP,并将该xml解析到SQL Server 2005的表中对于表值参数,您可以使用BulkInsertIn。。我有多个需要执行insert查询的表。所以我需要为每个表创建单独的用户定义类型吗?这取决于,在表值参数中可以有任意多的列。但是如果你告诉我你的要求,我可以帮你更好。