2011-07-29 26 views

答えて

0
PrivateFunction GetDataFromDb(ByVal lcSQL AsString, ByVal loCommandType As CommandType, _ 
    ByVal lcTableName AsString, ByValParamArray loParameters() As SqlParameter) As DataSet 

    Dim loResult As DataSet 
    Dim loConnection As SqlConnection 
    Dim loCommand As SqlCommand 
    Dim loAdapter As SqlDataAdapter 
    Dim i As Int32 
    Dim loParameter As SqlParameter 

    Try 

     'Create and open connection to the Northwind database 
     loConnection = New SqlConnection("Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=(local);Connect Timeout=30") 
     loConnection.Open() 

     'Prepare command and to select data from the database 
     loCommand = New SqlCommand(lcSQL, loConnection) 
     loCommand.CommandType = loCommandType 

     IfNot loParameters IsNothingThen 
      ForEach loParameter In loParameters 
       loCommand.Parameters.Add(loParameter) 
      Next 
     EndIf 

     loAdapter = New SqlDataAdapter(loCommand) 

     loResult = New DataSet 
     loAdapter.Fill(loResult, lcTableName) 

     'Return list of the customers as a DataSet 
     Return loResult 

    Catch ex As Exception 
     Throw ex 
    Finally 

     'Clean resources 
     IfNot loAdapter IsNothingThen 
      loAdapter.Dispose() 
      loAdapter = Nothing 
     EndIf 

     IfNot loCommand IsNothingThen 
      loCommand.Dispose() 
      loCommand = Nothing 
     EndIf 

     IfNot loConnection IsNothingThen 

      If loConnection.State = ConnectionState.Open Then 
       loConnection.Close() 
      EndIf 

      loConnection.Dispose() 
      loConnection = Nothing 

     EndIf 
    EndTry 

EndFunction 

http://support.microsoft.com/kb/555266

+0

おかげでみんな..これらを試してみようとあなたに知らせる – DQELER

+0

datatableはどこですか? – clweeks

0

は、XMLデータ型としてそれを渡し行う方法について、この記事を読んで、私はちょうど数ヶ月前にこれをしました。だから私はそれを処理するいくつかのコードを見つけるときに私は編集し直します。

Private Function AddToList(dtData As DataTable) As List(Of [Integer]) 
Dim ListOfInt As New List(Of Integer)() 
For Each row As DataRow In dtData.Rows 
    For Each Col As DataColumn In dtData.Columns 
     ListOfInt.Add(row(Col).ToString()) 
    Next 
Next 
Return ListOfInt 
End Function 
Private Function DataToXML() As XDocument 
     Dim DataDoc As XDocument = <?xml version='1.0'?> 
            <Root> 
             <%= RenderKeys(SelectedDataValues) %> 
            </Root> 
     Return DataDoc 
End Function  
Private Function RenderKeys(ByVal keys As List(Of Integer)) As Collection(Of XElement) 
     Dim ElementCollection As New Collection(Of XElement) 
     For Each Key As Integer In keys 
      Dim XKey As XElement = <Key ID=<%= Key %>/> 
      ElementCollection.Add(XKey) 
     Next 
     Return ElementCollection 
End Function 

これはちょうどその後、あなたのSPROCにちょうど入ってくるデータのXMLデータ型を追加するSQLサーバーから引き出されたテーブルからIDのリストを受け取り、(整数の)リストにそのに各IDを追加。で発見

+0

よりksみんな...私はtheeseを試してみようとあなたに知らせる – DQELER

関連する問題