Vb.net .net Framework 1.0如何从数据库访问数据并在文本框中显示

时间:2015-11-01 15:45:54

标签: vb.net winforms ado.net

我在Vb.net Win表单中使用.net framework 1.0,问题是如何从数据库中访问数据并在文本框中显示特定的列和行。 我在Gridview中显示数据,但我想在标签和文本框中显示一些数据。

Public Dim ConnectionString As New SqlConnection( "Data Source=.;Initial Catalog=WtfImaga;Integrated Security=True" )

Public  SqlDataAdapter As New SqlDataAdapter( "SELECT *   FROM wu.dbo.Students",ConnectionString )

Public  SqlDataSet As New DataSet

Public SqlcommandBuil As New SqlCommandBuilder(SqlDataAdapter)

并且onclick我可以显示加载到GridView上的数据,但我想在标签上显示学生名称

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

            SqlDataSet.clear()
DataGridView1.DataSource = SqlDataSet
DataGridView1.DataSource = Nothing

        SqlDataAdapter.Fill(SqlDataSet ,"Students")
        DataGridView1.DataSource = SqlDataSet.Tables("Students")
   TextBox1.Text = SqlDataAdapter.Fill(SqlDataSet,"Students.StudentId")
    End Sub 

1 个答案:

答案 0 :(得分:1)

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

        SqlDataSet.clear()
         DataGridView1.DataSource = SqlDataSet
         DataGridView1.DataSource = Nothing

         SqlDataAdapter.Fill(SqlDataSet ,"Students")
         DataGridView1.DataSource = SqlDataSet.Tables("Students")
         TextBox1.Text = SqlDataSet.Tables("Students").Rows(0).Item("StudentId")
End Sub 

显示数据集

中某一行的学生ID