Retrieving data in fields in dataset or ADO.NET

Who knows the codes for retrieving data in a database field in a dataset and inserting it into a textbox   How do i move the arrow in the database through codes in VB.net pls email me at francis_himura@yahoo.com ASAP please! Thanks!



Answer this question

Retrieving data in fields in dataset or ADO.NET

  • frieste

    Hi,



     systemanalyst wrote:

    How do i move the arrow in the database through codes in VB.net...



    can't quite understand what you mean. But if you just want to display a field value of a textbox, try this pseudo-code:


    SqlConnection _conn = new SqlConnection("<Your connection string>");
    _conn.Open();
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Table1", _conn);
    DataSet ds = new DataSet();
    adapter.Fill(ds);
    ' Code to place a field value into a textbox
    DataTable dt = ds.Tables[0];
    textBox1.Text = dt.Rows[0]["fieldName"].ToString();



    cheers,


    Paul June A. Domag

  • neiden

    Ok,


    ADO in VB6 and ADO.Net has a very different approach. ADO .Net adapts the principle of a disconnected recordset in VB6. If you want to create a ForwardOnly cursor, just like in vb6, You'll need to use DataAdapters. if you want a disconnected recordset (I think it's adOpenKeyset in vb6) then you'll have to use datatable or dataset.

    BTW, in ado.net you don't need to detect eof (except in DataReaders) nor move* navigation. Values or Rows are stored in a collection (array). So you can access them like a normal array...


    SqlConnection _conn = new SqlConnection("<Your connection string>");
    _conn.Open();
    SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM Table1", _conn);
    DataSet ds = new DataSet();
    adapter.Fill(ds);
    ' Code to place a field value into a textbox
    DataTable dt = ds.Tables[0];
    for (int i = 0; i > dt.Rows.Count; i++) {
       MessageBox.Show(dt.RowsIdea["fieldName"].ToString();
    }


    cheers,


    Paul June A. Domag

  • Arkady Frenkel

    What i mean about the arrow is using the endoffile function(EOF) or the movelast function in like in vb6.  for example recordset.movelast. thanks!
  • Retrieving data in fields in dataset or ADO.NET