这就是我正在尝试的......
Dim myCommand as SqlCommand
Dim myTable as New xsdObject.ObjectDataTable
myCommand = DataAccess.GetSQLCommand( "MyStoredProc", _
CommandType.StoredProcedure, SourceServer.ConnectionLocal)
myCommand.Connection.ChangeDatabase("MyDatabase")
myCommand.Parameters.AddWithValue("@Parameter", DataValue)
ExecuteSQLCommand(myCommand, myTable)
'How to access my data ?
答案 0 :(得分:5)
这是一个没有数据表的示例,如您的评论中所述。
Dim reader As SqlDataReader= MyCommand.ExecuteReader
Dim MyList as new List(Of WhateverObject)
Do While reader.Read
Dim obj as new WhateverObj
obj.Property1 = Reader.GetInt32(0)
obj.Property2 = Reader.GetString(1)
MyList.add(obj)
Loop
reader.Close()
myCommand.Dispose()
为了与标题匹配的完整答案,使用数据集:
Dim Adapter As New SqlDataAdapter(myCommand)
Dim ds As DataSet = New DataSet
Adapter.Fill(ds)
数据表:
Dim resultTable as DataTable = ds.Tables(0)
答案 1 :(得分:2)
要将结果放在DataTable
中,您需要在SqlDataAdapter
周围创建SqlCommand
并调用其Fill
方法。