2013-09-23 54 views

回答

-1

這是我希望可以幫助讀取SQL,它可能需要一點編輯和建設,但我仍然希望它可以幫助。

Dim conString As String = "data source=ServerName;" & _ 
          "initial catalog=DBName;" & _ 
          "integrated security=SSPI;" & _ 
          "persist security info=false;" 

Dim conSQL As New SqlConnection(conString) 

conSQL.Open() 

Dim cmdSQL As New SqlCommand() 
cmdSQL.CommandType = Data.CommandType.Text 
cmdSQL.CommandText = "SELECT FieldName1, FieldName2 FROM MyTable" 

Dim adptSQL As New SqlClient.SqlDataAdapter(cmdSQL) 
Dim myDataSet As New DataSet() 
adptSQL.Fill(myDataSet) 

conSQL.Close() 

With myDataSet.Tables(0) 
    For rowNumber As Integer = 0 To .Rows.Count - 1 
     With .Rows(rowNumber) 
      Console.WriteLine(String.Format("Field1: {0}, Field2: {1}", _ 
              .Item(0).Value.ToString, _ 
              .Item(1).Value.ToString)) 
     End With 
    Next 
End With 
相關問題