将数据从数据库显示到VB.Net应用程序的最佳方法?

时间:2013-09-23 07:21:35

标签: vb.net

我现在正在制作我的贷款管理应用程序,我只是想问一下在VB.Net中查看贷款​​数据的最佳方法是什么?顺便说一句,我使用MySQL作为数据库。

1 个答案:

答案 0 :(得分:-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