SqlParameter 问题
我想学习一下关于SqlParameter 执行SQL,但下面不知到出错在哪。望大家指点程序代码:
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 '不知怎么老出错
[此贴子已经被作者于2016-12-14 16:29编辑过]