locked
How to show data record in textbox ? RRS feed

  • Question

  • Please any genius can help me about how to display record in text box.....

     and my database is attached in my project not with sql .. like this

    Dim std As New DataSet1TableAdapters.RegistrationTableAdapter
    

    with this connection how i show data record in text box please every one


    Student
    Monday, December 26, 2011 8:48 PM

Answers

  • I cannot see what it is because it is generated, but probably it has to be something like

    Dim DataTable1 As New DataSet1.RegistrationDataTable
     
    dim std As New DataSet1TableAdapters.RegistrationTableAdapter
     
    std.Fill(DataTable1)
     
    TextBox1.Text = Cstr(DataTable1.StudentIDRow(0))
    


    Success
    Cor
    • Marked as answer by Mark Liu-lxf Tuesday, January 3, 2012 8:08 AM
    Monday, December 26, 2011 10:17 PM
  • Hi Atta,

    Welcome to the MSDN forum.

    The DataAdapter Class represents a set of SQL commands and a database connection that are used to fill the DataSet and update the data source. So you can use the DataAdapter to get the result of SQL commands and fill it to the data table. At the same time, if you want to show all information about the table, I suggest you to use DataGridView Control instead of Textbox to show the data. Here is a simple sample, and you can change it fit for you.

     

        Using con As New SqlConnection( _
               "Data Source=.;Initial Catalog=testdb;Integrated Security=True")
                Dim constr As String = "SELECT StudentID FROM Registration ORDER BY StudentID DESC"
                Dim dataAdapter As New SqlClient.SqlDataAdapter(constr, con)
                Dim WTDataTable As New DataTable("Registration")
                dataAdapter.Fill(WTDataTable)
                DataGridView1.DataSource = WTDataTable
            End Using
    
    

    At the same time, you also can use TableAdapter, please refer to “How to: Create TableAdapter Queries”: http://msdn.microsoft.com/en-us/library/kda44dwy.aspx

    If you have any additional questions, please feel free to let me know.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Mark Liu-lxf Wednesday, December 28, 2011 7:16 AM
    • Marked as answer by Mark Liu-lxf Tuesday, January 3, 2012 8:08 AM
    Wednesday, December 28, 2011 7:08 AM

All replies

  • Then you have to use the table adapter to fill a table.

    std.Fill(DataSet1)

    And then you can bind or set the text to a textbox, for instance the first column of the first row in your dataset table 1

    textbox1.text = DataSet1.Tables(0).Rows(0).Item(0) 

    (Mostly that is no string but let us assume that).


    Success
    Cor
    Monday, December 26, 2011 8:58 PM
  • thanks for answer !

     sir i want to display just Name filed and  not all filed form table


    Student
    • Edited by Atta zaib Monday, December 26, 2011 9:09 PM
    Monday, December 26, 2011 9:08 PM
  • it is not working please help me

    Dim DataSet1 As New DataSet1.RegistrationDataTable
     
            Dim std As New DataSet1TableAdapters.RegistrationTableAdapter
     
            DataSet1.Select("Select StudentID from Registration ")
     
            std.Fill(DataSet1)
     
            TextBox1.Text = DataSet1.StudentIDColumn(0).Rows(0).Item(0)

     

    this is error dataset1.studentIDcoloum


    Student
    Monday, December 26, 2011 10:09 PM
  • I cannot see what it is because it is generated, but probably it has to be something like

    Dim DataTable1 As New DataSet1.RegistrationDataTable
     
    dim std As New DataSet1TableAdapters.RegistrationTableAdapter
     
    std.Fill(DataTable1)
     
    TextBox1.Text = Cstr(DataTable1.StudentIDRow(0))
    


    Success
    Cor
    • Marked as answer by Mark Liu-lxf Tuesday, January 3, 2012 8:08 AM
    Monday, December 26, 2011 10:17 PM
  • Thanks you So much !

    it is working and please need like this

     Dim DataTable1 As New DataSet1.RegistrationDataTable
    
    Dim std As New DataSet1TableAdapters.RegistrationTableAdapter 'DataTable1.Select("SELECT StudentID FROM Registration ORDER BY StudentID DESC")
    std.Fill(DataTable1) TextBox1.Text = CStr(DataTable1.Rows(0).Item(0))

    called StudentID in to textbox by ORDER By DESC

    please please please

     


    Student
    Monday, December 26, 2011 10:44 PM
  • Hi Atta,

    Welcome to the MSDN forum.

    The DataAdapter Class represents a set of SQL commands and a database connection that are used to fill the DataSet and update the data source. So you can use the DataAdapter to get the result of SQL commands and fill it to the data table. At the same time, if you want to show all information about the table, I suggest you to use DataGridView Control instead of Textbox to show the data. Here is a simple sample, and you can change it fit for you.

     

        Using con As New SqlConnection( _
               "Data Source=.;Initial Catalog=testdb;Integrated Security=True")
                Dim constr As String = "SELECT StudentID FROM Registration ORDER BY StudentID DESC"
                Dim dataAdapter As New SqlClient.SqlDataAdapter(constr, con)
                Dim WTDataTable As New DataTable("Registration")
                dataAdapter.Fill(WTDataTable)
                DataGridView1.DataSource = WTDataTable
            End Using
    
    

    At the same time, you also can use TableAdapter, please refer to “How to: Create TableAdapter Queries”: http://msdn.microsoft.com/en-us/library/kda44dwy.aspx

    If you have any additional questions, please feel free to let me know.


    Mark Liu-lxf [MSFT]
    MSDN Community Support | Feedback to us


    • Edited by Mark Liu-lxf Wednesday, December 28, 2011 7:16 AM
    • Marked as answer by Mark Liu-lxf Tuesday, January 3, 2012 8:08 AM
    Wednesday, December 28, 2011 7:08 AM
  • thanks for answer ! i got it ! thanks
    Student
    Friday, December 30, 2011 6:43 PM