Yes, I know I can use SqlCommand object as I have been using them more often than SqlDataSource objects. The thing is I have data loaded with this SqlDsInvoice and displayed properly in a GridView. I don't want to use another call with SqlCommand to the
server to retrieve the same data set again. However, if I cannot solve this mystery today, I might just go ahead to submit an extra SqlCommand call. Thanks.
You made it sound like using SqlDataSource is evil... :)
Thanks, but I have already tested the DataView approach before and after oned-gk suggested yesterday. It failed with the same reason I stated afterward.
It might have something to do with my querystring supplying the parameters to the SqlDataSource ... need some more tests.
Whoa, I was not aware that some cheeky people could mark their own reply "as answer" while their contributions were just repeating others. Better mark the real contributors to make sure...
Gridview with SqlDataSource controls are a perfect solutions for many business situations and for rapid development, especially since .Net 4. They become so flexible and feature-rich. If you have been using SqlCommand and all sort of code behind programming
manually for the last decade, you would have a hard time to adopt these new controls. You should learn better.
Thanks to sinedyip and
oned_gk for inspiring me to look harder into the viewstate and the control's html code. I was planning to create a clean project with just the Gridview, SqlDataSource, and Textbox controls to prove to you guys the controls were problematic, but then it
actually worked - the Textbox did get data from the SqlDataSource in the first load! So I looked back to locate the differences between the codes and found the extra caching definitions in my original SqlDataSource control code. I deleted them to make it the
same as the new code but it still didn't work. As then I have seen the SqlDataSource did work with Textboxes, I had more confident to make it work.
Finally, I removed the whole SqlDataSource control object and recreated it with default settings and my original project worked! I added back the cache settings and it still worked. That's weird. However, over the years I have found a few times controls
added using Visual Studio's Designer graphical interfaces would introduce hidden codes that break mysteriously in unexpected situations. I think this is just another case of that sort.
So thanks everyone. I would say this is just a one time Designer glitch. The SqlDataSource control is fine.
Darain
Member
1 Points
10 Posts
Re: How to get data from SqlDataSource to populate non- data controls
Jan 03, 2013 02:45 PM|LINK
Yes, I know I can use SqlCommand object as I have been using them more often than SqlDataSource objects. The thing is I have data loaded with this SqlDsInvoice and displayed properly in a GridView. I don't want to use another call with SqlCommand to the server to retrieve the same data set again. However, if I cannot solve this mystery today, I might just go ahead to submit an extra SqlCommand call. Thanks.
Darain
Member
1 Points
10 Posts
Re: How to get data from SqlDataSource to populate non- data controls
Jan 03, 2013 02:51 PM|LINK
Here you go, the SqlDataSource HTML code:
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to get data from SqlDataSource to populate non- data controls
Jan 04, 2013 01:06 AM|LINK
If you insist using SqlDataSource……It returns you a DataTable instead of a DataReader。
The Select method returns a DataView object if the DataSourceMode property is set to the DataSet value. The Select method returns a IDataReader object if the DataSourceMode property is set to the DataReader value. Close the IDataReader object when you have finished reading the data.
For more you can refer this:
DataView dv = (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
int reorderedProducts = (int)dv.Table.Rows[0][0];
Darain
Member
1 Points
10 Posts
Re: How to get data from SqlDataSource to populate non- data controls
Jan 04, 2013 04:56 PM|LINK
You made it sound like using SqlDataSource is evil... :)
Thanks, but I have already tested the DataView approach before and after oned-gk suggested yesterday. It failed with the same reason I stated afterward.
It might have something to do with my querystring supplying the parameters to the SqlDataSource ... need some more tests.
Decker Dong ...
All-Star
118619 Points
18779 Posts
Re: How to get data from SqlDataSource to populate non- data controls
Jan 05, 2013 02:34 AM|LINK
Not absolute, but for you situation, it might be.
Darain
Member
1 Points
10 Posts
Re: How to get data from SqlDataSource to populate non- data controls
Jan 13, 2013 02:27 PM|LINK
Whoa, I was not aware that some cheeky people could mark their own reply "as answer" while their contributions were just repeating others. Better mark the real contributors to make sure...
Gridview with SqlDataSource controls are a perfect solutions for many business situations and for rapid development, especially since .Net 4. They become so flexible and feature-rich. If you have been using SqlCommand and all sort of code behind programming manually for the last decade, you would have a hard time to adopt these new controls. You should learn better.
Thanks to sinedyip and oned_gk for inspiring me to look harder into the viewstate and the control's html code. I was planning to create a clean project with just the Gridview, SqlDataSource, and Textbox controls to prove to you guys the controls were problematic, but then it actually worked - the Textbox did get data from the SqlDataSource in the first load! So I looked back to locate the differences between the codes and found the extra caching definitions in my original SqlDataSource control code. I deleted them to make it the same as the new code but it still didn't work. As then I have seen the SqlDataSource did work with Textboxes, I had more confident to make it work.
Finally, I removed the whole SqlDataSource control object and recreated it with default settings and my original project worked! I added back the cache settings and it still worked. That's weird. However, over the years I have found a few times controls added using Visual Studio's Designer graphical interfaces would introduce hidden codes that break mysteriously in unexpected situations. I think this is just another case of that sort.
So thanks everyone. I would say this is just a one time Designer glitch. The SqlDataSource control is fine.