Dim dtAdapter As New OdbcDataAdapter
Dim dt As New DataTable
objConn = New OdbcConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
objCmd = New OdbcCommand()
objCmd.Connection = objConn
objCmd.CommandText = PocedureName
For i As Integer = 0 To parameter.Length - 1
objCmd.Parameters.AddWithValue(parameter(i).ToString(), Values(i))
Next
objCmd.CommandType = CommandType.StoredProcedure
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(dt)
Return dt
Tag : .NET, Ms SQL Server 2005, Web (ASP.NET), VB.NET
Public Function QueryDataTableStoredPocedureWithParameter(ByVal PocedureName As String, ByVal parameter() As String, ByVal Values() As String) As DataTable
Dim dtAdapter As New OdbcDataAdapter
Dim dt As New DataTable
objConn = New OdbcConnection
With objConn
.ConnectionString = strConnString
.Open()
End With
objCmd = New OdbcCommand()
objCmd.Connection = objConn
objCmd.CommandText = PocedureName 'ชื่อ Procedure
For i As Integer = 0 To parameter.Length - 1
objCmd.Parameters.AddWithValue(parameter(i).ToString(), Values(i))
Next
objCmd.CommandType = CommandType.StoredProcedure 'กำหนดชนิดเป็น StoredProcedure
dtAdapter.SelectCommand = objCmd
dtAdapter.Fill(dt)
Return dt '*** Return DataTable ***'
End Function