|
Hi,
Ive got several DataLists on a page. Im using a method to fill the DataSet and Bind the data to each datagrid in turn. So im effectively re-using the same data set to get data from the same adapter and from the same table.
The only difference is that each DataList is to be populated based on different queries eg retreiving orders based on their category - food, drink, desserts etc.
The problem is, each time i fill the dataset it just adds the new content to the old, and thus each DataList displays the info obtained from the previous query strings.
Is there anyway to avoid this, or perhaps to flush the DataSet after i fill each DataList?
Thanks
munklefish
|
|
|
|
|
Hi Munklefish
We're gonna have to see some code to determine where it goes wrong.
It sounds more like the data is being added to the lists on top of what is already there.. but as I said - post some code and we'll catch that bug
The code you're looking for to empty a datatable is:
dtMyDataTable.Clear();
More specifically - let's see where you
- fill the datasets/datatables
- add data to the lists
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
-- modified at 16:56 Friday 14th April, 2006
|
|
|
|
|
Ok, Heres how i call method on Page_Load
loadDDL("tapas");<br />
loadDDL("paellas");<br />
loadDDL("postres");<br />
loadDDL("desserts");<br />
loadDDL("bebidas");<br />
loadDDL("vinos");
And here is the contents of the method:
private void loadDDL(string input)<br />
{<br />
string checksql="SELECT * FROM tbl_Orders WHERE orderTableID = '"+tmpTable+"' AND orderUserID = '"+tmpCustLast+"' AND orderCategory = '"+input+"' AND (OrderTime BETWEEN '"+preDate+"' AND '"+dateNow+"') ORDER BY orderTime DESC, orderUpdated DESC";<br />
myAdapter.SelectCommand.CommandText=checksql;<br />
myAdapter.Fill(dataSet11, "tbl_orders");<br />
switch(input)<br />
{<br />
case "tapas":<br />
{<br />
DataList1.DataSource= dataSet11;<br />
DataList1.DataBind();<br />
break;<br />
}<br />
case "paellas":<br />
{<br />
DataList2.DataSource= dataSet11;<br />
DataList2.DataBind();<br />
break;<br />
}<br />
case "postres":<br />
{<br />
DataList3.DataSource= dataSet11;<br />
DataList3.DataBind();<br />
break;<br />
}<br />
case "desserts":<br />
{<br />
DataList4.DataSource= dataSet11;<br />
DataList4.DataBind();<br />
break;<br />
}<br />
case "bebidas":<br />
{<br />
DataList5.DataSource= dataSet11;<br />
DataList5.DataBind();<br />
break;<br />
}<br />
case "vinos":<br />
{<br />
DataList6.DataSource= dataSet11;<br />
DataList6.DataBind();<br />
break;<br />
}<br />
<br />
<br />
}<br />
<br />
}
Rather than the new results overwritting the old in the DataSet, they are being added to it.
P.s Jakob,
Jakob Lund Krarup wrote: 10 kinds of people in the world:
- Those who understand binary
- Those who don't
I saw one of your posts ages ago and thought id add the binary joke as my footer in response to yours! I see you've adopted it now.
|
|
|
|
|
Hi Munklefish
You're right you need to add a line of code to your fill part.
Change :
munklefish wrote: myAdapter.SelectCommand.CommandText=checksql;
myAdapter.Fill(dataSet11, "tbl_orders");
To:
myAdapter.SelectCommand.CommandText=checksql;
dataSet11.Clear();
myAdapter.Fill(dataSet11, "tbl_orders");
That should do the trick.
munklefish wrote: P.s Jakob,
Jakob Lund Krarup wrote:
10 kinds of people in the world:
- Those who understand binary
- Those who don't
I saw one of your posts ages ago and thought id add the binary joke as my footer in response to yours! I see you've adopted it now.
hehe .. yup - I have it on a T-shirt, and your footer reminded me that it was the perfect companion to my own footer
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
Jakob Lund Krarup wrote: dataSet11.Clear();
Jakob,
How come this command has evaded me? Ive looked everywhere for something logical like this but have found no references! Even VS.Net doesnt give me any suitable response.
So much trouble for such a simple solution!!!
Thanks for the help!!!!
munklefish
|
|
|
|
|
Hi Munklefish
I know the feeling. It happens to us all.
There is also a Clear() method on the DataTable class, if you only want to clear a table, and not all tables in a DataSet.
You might consider storing the different tables in one dataset, and then storing the DataSet in Application, to make it easier on the database?
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
Jakob Lund Krarup wrote: You might consider storing the different tables in one dataset, and then storing the DataSet in Application, to make it easier on the database?
Jakob,
What does this involve, and how do i do it? I'm totally in this dark on this method.
Thanks!
Munklefish
|
|
|
|
|
Hi Munklefish
Well, now that I've looked your code over again, it seems that you fill the DataTable with very different data for each request, based on the search being done. The method I was referring to is most useful if you have a couple of tables that very seldomly change, then you can load those into Applicationstate (a piece of RAM on the webserver that is shared between all users).
It would work something along the lines of (coding from memory here - might need a bit of IntelliSense later ):
protected void LoadData()
{
if(Application["myData"] == null)
{
dsMyData = new DataSet();
SqlDataAdapter adapter = new SqlDataAdapter("SELECT * FROM orders", strConnectionString);
adapter.Fill(sdMyData, "orders");
Application["myData"] = dsMyData;
}
else
dsMyData = (DataSet)Application["myData"];
}
This requires your connectionstring to be in the variable strConnectionString and a DataSet named csMyData to be declared on the Page level. Then you can call the LoadData method from the PageLoad eventhandler, and you will always have the tables in RAM, except for the first time of course. Application is emptied when the last users Session times out (by default 20 minutes after his/her last click on the page).
Since you actually don't need the DataTables in the code you showed me, then the DataReader is actually faster for just getting stuff from the DataBase. (also from memory ... don't hit me if it's not perfect!)
SqlConnection connection = new SqlConnection("server=(local);database=shop;user=me;password=secret");
SqlCommand command = connection.CreateCommand();
command.CommandText = "SELECT * FROM orders WHERE ...yadayadayada...";
connection.Open();
dlOrders.DataSource = command.ExecuteReader();
dlOrders.DataBind();
connection.Close();
Hope this was of some use to you.
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
Jakob,
Very Interesting. Ill take a look at that when i have some time.
At the moment im struggling with some other stuff. (see my latest pst)
Thanks again!
Happy Easter!
|
|
|
|
|
munklefish wrote: Happy Easter!
you too
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
Jakob Lund Krarup wrote: hehe .. yup - I have it on a T-shirt.......
GEEK!
|
|
|
|
|
Hehe... - yup! (and proud of it - schhh )
Kind regards - Jakob
*********************************************
Three kinds of people in the world:
- Those who can count..
- Those who can't!
10 kinds of people in the world:
- Those who understand binary
- Those who don't
|
|
|
|
|
After I covert a 2005 Web Site Project to a 2005 Web Application Project, I got the following Error on a web reference which point to a web service. I removed the reference and add it again but got the same error:
Custom tool error: Unable to import WebService/Schema. Exception of type 'System.Exception' was thrown.
Any help is appreciated.
|
|
|
|
|
Having a huge problem using different IIS servers and one SQL Server State. When the user goes from computer A to B the B computer quicks him out to Login again.
Any solution?
Cheers
Al
My eMail control
My Blog
|
|
|
|
|
|
Thanks, that's what I did. Actually you need to compile a program to generate the machinekey. Just thought that could be added into the Service State to be better solution!
I am writing my own Session State, will see how it comes out
Thanks for all your help!
Al
My eMail control
My Blog
|
|
|
|
|
My project reqiures dispalying windows forms in ASP .NET so that any type of drawing is a possible. Pls could anyone tell me how to do this?
|
|
|
|
|
|
Hello,
I am trying to figure out how to get a textbox in a template field to autopostback. I added a text box to the item template and set the autopostback to true, and it does actually post back. However, I am trying to read information from that text box that caused the post back and I always get a null reference error. How do I make the text box content available in the TextChanged event within the Gridview? Thanks in advance.
Jason
|
|
|
|
|
I have the global.asax file, generated by Visual Studio 2005, with the usual Application_Error method, that's supposed to handle all uncatched exceptions in the web application.
Well, this method is never called, even when I force a NullReferenceException intentionally.
I'm using ASP.NET 2.0.
Does anyone can help me?
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
Hi Dario. What does your Application_Error code look like? Is it possible it is getting called, but not coded in such a way as to make that obvious?
Another possibility is if the exception is generated on a different thread than the main ASP.NET thread. Here's an article that describes it better than I can (Look about halfway down for ASP.NET specifics):
http://www.julmar.com/blog/mark/PermaLink,guid,f733e261-5d39-4ca1-be1a-c422f3cf1f1b.aspx[^]
|
|
|
|
|
Mike Ellison wrote: Hi Dario. What does your Application_Error code look like?
It simply writes in a log (SQL Server) a message including the exception.
Mike Ellison wrote: Another possibility is if the exception is generated on a different thread than the main ASP.NET thread.
I think that is the problem, because after a few tests I noticed that Application_Error has been called some times, but not all the times it should have been called.
Thanks!
___________________________________
Tozzi is right: Gaia is getting rid of us.
My Blog [ITA]
|
|
|
|
|
Looking for a little help. I have a web app that is timing out between 10 and fifteen minutes. The problem is that I have my Session State Timout set to 20 (in Web.Config) and my IIS AspSessionTimeout is set to 20 minutes.
Anyone have any ideas?
Thanks for your time and consideration,
-B
|
|
|
|
|
|
Thanks for the suggestion, but no I'm using:
<authentication mode="Windows">
Thanks again.
|
|
|
|