#2
不说也罢2016-12-16 18:43
|
程序代码:
Public Class SQLHelper
Public Function ExecuteDataTableSP(ByVal strSQLSP As String, ByVal params() As SqlParameter) As DataTable
Dim oconn As SqlConnection = GetConnection()
Dim command As New SqlCommand(strSQLSP, oconn)
command.CommandType = CommandType.text'为何StoredProcedure不能执行?改为text就完全没问题了
Dim dt As New DataTable
Dim da As New SqlDataAdapter(command)
For i As Integer = 0 To params.Length - 1
da.SelectCommand.Parameters.Add(params(i))
Next
da.Fill(dt)
da.Dispose()
oconn.Close()
oconn.Dispose()
command.Dispose()
Return dt
End Function
End Class
sub ExecuteSql()
Dim SqlCmd As SQLHelper = New SQLHelper
Dim paras As SqlParameter() = {New SqlParameter("@Model_Name", CStr(TextBox1.Text)),
New SqlParameter("@Part_Name", CStr(TextBox2.Text)),
New SqlParameter("@BuildStep", CStr(TextBox3.Text)),
New SqlParameter("@Per_Use", CInt(TextBox4.Text))}
Dim StrSql As String = "Select * from KanBanBom where Model_Name = @Model_Name and Part_Name = @Part_Name and BuildStep = @BuildStep"
Dim myTab As DataTable = SqlCmd.ExecuteDataTableSP(StrSql, paras)
If myTab.Rows.Count > 0 Then MsgBox("Check your data again", MsgBoxStyle.Information) : Exit Sub
end sub
'不知怎么老出错
Public Function ExecuteDataTableSP(ByVal strSQLSP As String, ByVal params() As SqlParameter) As DataTable
Dim oconn As SqlConnection = GetConnection()
Dim command As New SqlCommand(strSQLSP, oconn)
command.CommandType = CommandType.text'为何StoredProcedure不能执行?改为text就完全没问题了
Dim dt As New DataTable
Dim da As New SqlDataAdapter(command)
For i As Integer = 0 To params.Length - 1
da.SelectCommand.Parameters.Add(params(i))
Next
da.Fill(dt)
da.Dispose()
oconn.Close()
oconn.Dispose()
command.Dispose()
Return dt
End Function
End Class
sub ExecuteSql()
Dim SqlCmd As SQLHelper = New SQLHelper
Dim paras As SqlParameter() = {New SqlParameter("@Model_Name", CStr(TextBox1.Text)),
New SqlParameter("@Part_Name", CStr(TextBox2.Text)),
New SqlParameter("@BuildStep", CStr(TextBox3.Text)),
New SqlParameter("@Per_Use", CInt(TextBox4.Text))}
Dim StrSql As String = "Select * from KanBanBom where Model_Name = @Model_Name and Part_Name = @Part_Name and BuildStep = @BuildStep"
Dim myTab As DataTable = SqlCmd.ExecuteDataTableSP(StrSql, paras)
If myTab.Rows.Count > 0 Then MsgBox("Check your data again", MsgBoxStyle.Information) : Exit Sub
end sub
'不知怎么老出错
[此贴子已经被作者于2016-12-14 16:29编辑过]