0

I ask myself how I can display a single row from a datatable object in a control like a gridview.

I already did it with label objects like here: (this is in load event. I already have buttons which increment the zero and decrement)

 Tbname.Text = (dset.Tables("coduta").Rows(0).Item("Firma"))
        TbStraße.Text = (dset.Tables("coduta").Rows(0).Item("Straße_Firma"))
        TbHausnummer.Text = (dset.Tables("coduta").Rows(0).Item("Hausnummer_Firma"))
        TbOrt.Text = (dset.Tables("coduta").Rows(0).Item("Ort_Firma"))

the point is I want to show the specific row in something like a gridview control. The only Idea i have is, to create a new table out of the row and that looks like a too complicated way for this. I hope guys can help

cheers steven

2
  • so the point is you want to get first row of datatable into another datatable?? Commented Aug 21, 2015 at 7:11
  • No I want to display the first row in a gridview or a similar control. when I click the next button I want to display the next row. Commented Aug 21, 2015 at 7:18

2 Answers 2

1

I am from C# background but this approach should help you.

  1. Get first row from existing table.
  2. Make clone of existing table.
  3. Add that row to clone table.
  4. Assign that table as datasource for grid

    DataRow dr = dset.Tables("coduta").Rows(0); 
    DataTable dtNew = dset.Tables("coduta").Clone();
    dtNew.Rows.Add(dr.ItemArray);
    grid.DataSource = dtNew;
    grid.DataBind();
    
Sign up to request clarification or add additional context in comments.

3 Comments

does clone only clone the scheme?
yes. With contraints and no data is copied. try it.
This is how I do it now. It is not what I wish to archive but it works. Cheers and thx
0

try

da = new SqlDataAdapter();
DataSet ds = new DataSet();
DataTable dt = new DataTable();

da.SelectCommand = new SqlCommand(@"SELECT * FROM coduta", connString);
da.Fill(ds, "coduta");
dt = ds.Tables["coduta"];

foreach (DataRow dr in dt.Rows)
{
    //here is your row of data
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.