locked
Get Data From DataAdapter and set to a lable text property

    Domanda

  • I have a dataset to connect my SQL Server database and create a query GetDataFromMyParameter.

    I tried to use

    MyLable.Text = MyDataSet.GetDataFromMyParameter(MyData)

    but it does not work.

    Can you please advise how I can read data from tableadapter or I am not on the right track?

    Your informaiton and help is great appreciated,

    Regards,

    Sourises,

    lunedì 22 ottobre 2012 16:25

Risposte

  • Hi sourises,

    Thanks for you post.

    You need to load the data from tableadapter to the dataset/datatable firstly. And use the dataset/datatable to show in the textbox.

    Please refer this link to get How to: Fill a Dataset with Data: http://msdn.microsoft.com/en-us/library/ms171920(v=vs.100).aspx

    As for the way loading data form datatable, there is two ways.

    One way is that load one specific data to lable, here is just a sample:

      Dim dt As New DataTable
           'load the data to datatable
            'the integer is the index of row and column (start with 0)
             Label1.Text = dt.Rows(0).Item(0).ToString

    If there is lots of data in it, you can use the datagridview to display the data. Just bind the datatable with datagridview:

    DataGridView1.DataSource = dt

    Hope this helps.


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

    • Contrassegnato come risposta sourises martedì 23 ottobre 2012 15:27
    martedì 23 ottobre 2012 05:25
    Moderatore

Tutte le risposte

  • Hi sourises,

    Thanks for you post.

    You need to load the data from tableadapter to the dataset/datatable firstly. And use the dataset/datatable to show in the textbox.

    Please refer this link to get How to: Fill a Dataset with Data: http://msdn.microsoft.com/en-us/library/ms171920(v=vs.100).aspx

    As for the way loading data form datatable, there is two ways.

    One way is that load one specific data to lable, here is just a sample:

      Dim dt As New DataTable
           'load the data to datatable
            'the integer is the index of row and column (start with 0)
             Label1.Text = dt.Rows(0).Item(0).ToString

    If there is lots of data in it, you can use the datagridview to display the data. Just bind the datatable with datagridview:

    DataGridView1.DataSource = dt

    Hope this helps.


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

    • Contrassegnato come risposta sourises martedì 23 ottobre 2012 15:27
    martedì 23 ottobre 2012 05:25
    Moderatore
  •  

    dt = TableAdapter.GetData()

    MyLabel.Text = dt.Rows(2).Item(2).ToString

    Thanks for helping,

    I use above code which works, but this code fills the whole table.

    Is it possible to get only one row and one column of data by the paramter by user like folowing?

    Dim MyParam as string

    dt = TableAdapter.GetData(MyParam)

    Thanks again for helping,

    Sourises,

    martedì 23 ottobre 2012 14:35
  • Thanks a million for the information and help,

    Regards,

    Sourises,

    martedì 23 ottobre 2012 15:27
  • Hi sourises,

    It is strange that you get all data of the table.

    Please check the code in form load event whether you have filled the tableadater with the datatable. If yes, just use this datatble (do not need to create a new datatable). Here is a sample:

       Private Sub Form3_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
            'TODO: This line of code loads data into the 'TestdbDataSet.testtb' table. You can move, or remove it, as needed.
            Me.TesttbTableAdapter.Fill(Me.TestdbDataSet.testtb)
            'Just use the "Me.TestdbDataSet.testtb" datatable
            MyLabel.Text = Me.TestdbDataSet.testtb.Rows(1).Item(1).ToString
        End Sub

    Hope this helps.


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

    mercoledì 24 ottobre 2012 02:20
    Moderatore