Dis*_*oat 2 vb.net stored-procedures
由于某种原因,我的存储过程都执行了两次!我有一个静态函数,它运行SP给定其名称和参数并填充数据表.
Public Shared Function RunSP(ByVal spName As String, ByRef spParams As Dictionary(Of String, String), ByRef pDataTable As DataTable) As Integer
Dim cmd As New SqlCommand
Dim lAdapter As SqlDataAdapter
Try
cmd.Connection = New SqlConnection(ConnectionString)
cmd.Connection.Open()
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = spName
For Each item As KeyValuePair(Of String, String) In spParams
cmd.Parameters.AddWithValue(item.Key, item.Value)
Next
cmd.ExecuteNonQuery()
If Not pDataTable Is Nothing Then
lAdapter = New SqlDataAdapter(cmd)
lAdapter.Fill(pDataTable)
End If
RunSP = 0
Catch ex As Exception
If (Not cmd Is Nothing) Then
cmd.Dispose()
End If
RunSP = -1
End Try
End Function
Run Code Online (Sandbox Code Playgroud)
代码有问题吗?我已经检查过调试器,并且相应的SP肯定只被调用一次,即这个函数只对特定的插入函数运行一次,但是在表中插入了两个东西.
Mar*_*ell 12
你手动执行它(cmd.ExecuteNonQuery()),然后适配器将执行一次(New SqlDataAdapter(cmd)... Fill(...)).这样两次.你的意思是为适配器使用不同的命令吗?
| 归档时间: |
|
| 查看次数: |
2346 次 |
| 最近记录: |