ayou
ayou

Reputation: 33

convert dataset to datatable c#

ds.Tables.Add(dt);
da = new SqlDataAdapter(
  @"select Time1, Time2, EndDate from Event 
    where Venue ='" + txtVenue.Text + "', 
    StartDate ='" + cbStartMonth.Text + "/" + 
    cbStartDay.Text + "/" + 
    DateTime.Today.Year + "'" ,conn);
da.Fill(dt);

i'm sorry for the confusion, the code actually works but the problem is now how to view data coming from the data table

Upvotes: 1

Views: 25259

Answers (4)

Suresh klt
Suresh klt

Reputation: 59

you can use

ds.Table.Add(dt);
    DataTable dt1=ds.Tables[0];

Upvotes: -1

SolidRegardless
SolidRegardless

Reputation: 537

I would also change your code to use parameters. Otherwise you are leaving yourself open for serious SQL injection attacks all over the place.

Look here for an example of how to use parameters with your SqlDataAdapter. http://msdn.microsoft.com/en-us/library/bbw6zyha(v=vs.71).aspx

It also answers your question.

HTH SR

Upvotes: 0

Dave Zych
Dave Zych

Reputation: 21897

A DataSet is a collection of DataTables. You don't convert from one to the other, one stores the other.

If only 1 row is showing up, then your Sql is only returning a single row.

Upvotes: 2

Aghilas Yakoub
Aghilas Yakoub

Reputation: 29000

Just you adjust with .Tables property

var result = yourDataSet.Tables[0];

Your table is empty because you can adjust your query with and between clauses

But you rewrite your query ( You add and operator)

da = new SqlDataAdapter("select Time1, Time2, EndDate from Event 
where Venue ='" + txtVenue.Text + "' AND 
StartDate ='" + cbStartMonth.Text + "/" + 
cbStartDay.Text + "/" + 
DateTime.Today.Year + "'" ,conn);

Upvotes: 1

Related Questions