English 中文(简体)
VB.NET:我如何利用ExecuteSQLCommand并将我的数据输入数据表和查阅?
原标题:VB.NET: How can I use ExecuteSQLCommand and return my data in a datatable and access it?

This is what I m trying...

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 ?
最佳回答

Here is an example without the datatable, as mentioned in your comment.

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)

The Datatable:

Dim resultTable as DataTable = ds.Tables(0)
问题回答

为了将结果列入<代码> 可发射,你需要围绕<代码>SqlDataAdapter,并打电话到





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Transaction handling with TransactionScope

I am implementing Transaction using TransactionScope with the help this MSDN article http://msdn.microsoft.com/en-us/library/system.transactions.transactionscope.aspx I just want to confirm that is ...

System.Web.Mvc.Controller Initialize

i have the following base controller... public class BaseController : Controller { protected override void Initialize(System.Web.Routing.RequestContext requestContext) { if (...

Microsoft.Contracts namespace

For what it is necessary Microsoft.Contracts namespace in asp.net? I mean, in what cases I could write using Microsoft.Contracts;?

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签