943,741 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Unsolved
  • Views: 2359
  • C# RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Jan 9th, 2009
0

Re: DML operation on Dataset

Iterating through the DataSet:

Here is a simple code to iterate through the dataset and select individual items instead of selecting all the data in the DataSet.

SqlDataAdapter ad = new SqlDataAdapter("SELECT * FROm Categories",myConnection);

DataSet ds = new DataSet();

ad.Fill(ds,"Categories");

DataTable dt = ds.Tables["Categories"];


Response.Write(dt.Rows[0][1].ToString()) ;

1) First few lines are identical which we have done before.

2) In the forth line we declared the DataTable object. DataTable object is used to hold a single table. As I already told you that dataset can hold multiple tables depending upon the query so we can assign a single table from the dataset to the datatable object. I have done that using the line.

DataTable dt = ds.Tables["Categories"];

3) Next we are printing the first row of the second column. Always remember that the number of the rows and columns in the database does not start with 1 but it starts at 0. So in this line of code:

Response.Write(dt.Rows[0][1].ToString()) ;

This line of code means that get Row '0' and Column 1 of the from the datatable. And so we get the value and it prints out "Beverages".

Saving dataSets in Session State:

DataSets can also be saved in the Session State so that it can be available in other areas of the application and in new pages. The way of storing the DataSet in Session State is very easy.

Session["MyDataSet"] = DataSet;

Later if you want to retrieve the DataSet from the Session State you can easily do this by using this line of code:

DataSet ds = (DataSet) Session["MyDataSet"]

As you can see that when I am retrieving the values from the Session object I am casting it into the dataset object. This is because this is explicit conversion and requires casting. I am unboxing in this case.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
mr.mukesh is offline Offline
2 posts
since Jan 2009
Jan 30th, 2009
0

Re: DML operation on Dataset

hi currently i m using.

connection=new oledbconnection(oracle connection);
connection.open();
command=new oledbcomman("select * from table_name");
adapter=new oledbdataadapter(command);
adapter.fill(dataset,"Tableinfo");


now i need to get the data from the dataset using only DML.

i tried the following coding but its not working.

conn= new oledbconnection("Provider=SQLOLEDB; server=(local);integrated security=SSPI; database=northwind");
conn.open(); // exception occur in this place.

command = new oledbcommand("Select column from Tableinfo", conn);
.......................

please give an idea i tried many times and still i m face the problem.........
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
karthi_selva is offline Offline
65 posts
since Oct 2008
Jan 30th, 2009
0

Re: DML operation on Dataset

Click to Expand / Collapse  Quote originally posted by LizR ...
We will help you, but we wont write anything for you. google, has nearly all the answers you could need. Have a look.
hi currently i m using.

connection=new oledbconnection(oracle connection);
connection.open();
command=new oledbcomman("select * from table_name");
adapter=new oledbdataadapter(command);
adapter.fill(dataset,"Tableinfo");


now i need to get the data from the dataset using only DML.

i tried the following coding but its not working.

conn= new oledbconnection("Provider=SQLOLEDB; server=(local);integrated security=SSPI; database=northwind");
conn.open(); // exception occur in this place.

command = new oledbcommand("Select column from Tableinfo", conn);
.......................

please give an idea i tried many times and still i m face the problem.........
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
karthi_selva is offline Offline
65 posts
since Oct 2008
Feb 11th, 2009
0

Re: DML operation on Dataset

The only easiest method is
LINQ
Reputation Points: 10
Solved Threads: 0
Junior Poster in Training
karthi_selva is offline Offline
65 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: Porblem in DataGrid
Next Thread in C# Forum Timeline: how to add the data into datagrid view





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC