Asked by:
Clearing gridview

Question
-
User-2094959909 posted
Hello everyone,
in my application i have to add a product with its price and name ... also to database of course so that i show all my products in a gridview with total of prices
i have an issue that i have to clear gridview of all items in the end of the day so that the database also needed to be cleared of course
if anybody can help please don't hesitate
thanks in advance.
Saturday, November 3, 2018 8:01 PM
All replies
-
User409696431 posted
Your question is rather confusing. You want to clear the database of all your data at the end of the day? That seems to be a strange requirement, but if you really want to do that just run a delete command to delete all the rows. If your gridview is bound to data from a table that is empty, the gridview will be blank (or show the emptydatatemplate, if you have one).
Saturday, November 3, 2018 8:09 PM -
User-1716253493 posted
Seem like you need to save current datevalue to the database and show only current date data. You don't need to clear the data.
Sunday, November 4, 2018 4:17 AM -
User-2094959909 posted
That seems to be a strange requirement,
Yes KathyW i found it strange too but this is what i was asked to do so i need to do so
but thank you i will try to run a delete command
Sunday, November 4, 2018 11:30 AM -
User-2094959909 posted
oned_gk
how can i show onlu current date data ?
if you can help me please
Sunday, November 4, 2018 11:32 AM -
User-1716253493 posted
select * from tbl where cast([datecol] as date) = cast(getdate() as date)
if datecol doesn't contain time part you dont need cast function
Sunday, November 4, 2018 1:51 PM -
User-2094959909 posted
Hello,
i have filled my gridview wit sqldatasource not with DataBind() so now i have a button named clear that i want when to be clicked on the gridview will be cleared also from database where all the data of gridview are on
Thanks in advance
Wednesday, November 7, 2018 7:58 PM -
User475983607 posted
i have filled my gridview wit sqldatasource not with DataBind() so now i have a button named clear that i want when to be clicked on the gridview will be cleared also from database where all the data of gridview are on
You have to realize that we cannot accurately answer this question. I recommend that you go through the docs to see if the reference docs answer your question.
Wednesday, November 7, 2018 8:17 PM -
User-1716253493 posted
Do you want clear all data from the table?
Simply set sqldatasource delete command with no criteria, such as delete from yourtable
DeleteCommand = "DELETE FROM table_name"
or with same select criteria, clear button clicked event
sqldatasource1.Delete() Gridview1.DataBind()
Thursday, November 8, 2018 12:35 AM -
User61956409 posted
Hi Omar27,
i have to clear gridview of all items in the end of the day so that the database also needed to be cleared of courseIf you'd like to automatically clear/delete the old data at the end of the day (a specified time), you can use and run a scheduled task/job to achieve it.
i have filled my gridview wit sqldatasource not with DataBind() so now i have a button named clear that i want when to be clicked on the gridview will be cleared also from database where all the data of gridview are onIf you'd like to delete the records that are displayed in current GridView control from your database table (not want to delete/drop a table from your database). You can delete records that fulfill specified conditions in button click event from code behind.
protected void btnclear_Click(object sender, EventArgs e) { //Delete records that fulfill a specified condition //SQL Query: DELETE FROM table_name WHERE condition
//Your code logic here SqlDataSource1.DataBind(); }Note: the records that you deleted would not be available again. If possible, you can add/use a filed that indicates if the record is available in your table instead of directly deleting the record.
With Regards,
Fei Han
Friday, November 9, 2018 7:07 AM