Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Sep 22, 2009 07:03 PM by Mikesdotnetting
Member
8 Points
54 Posts
Sep 22, 2009 06:20 PM|LINK
How do I execute a SQL query within a VB sub triggered by an event such as a page load or other event?
I want to remove out-dated records from a table before data is displayed to the user.
Here is the query I'd like to run:
DELETE FROM t_Event WHERE (EventDate < GETDATE())
All-Star
155593 Points
19979 Posts
Moderator
MVP
Sep 22, 2009 06:35 PM|LINK
Rather than firing an SQL command every time someone requests a page, why not just show ones that are still current?
SELECT * From t_Event WHERE EventDate >= GetDate()
81342 Points
11398 Posts
Sep 22, 2009 06:39 PM|LINK
* IF you still do want to clean up every time before you load data *
follow the example over here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx
instead of
Dim commandText As String = _ "UPDATE Sales.Store SET Demographics = @demographics " _ & "WHERE CustomerID = @ID;"
you'll have your delete statement, and you won't need to add Parameters, as in these lines
command.Parameters.Add/AddWithValues
whereas, rowsAffected will give you how many records were deleted.should be simple....
Contributor
2385 Points
403 Posts
Sep 22, 2009 06:43 PM|LINK
Check this link
http://www.dreamincode.net/code/snippet1212.htm
Sep 22, 2009 07:03 PM|LINK
lohith.bn Check this link http://www.dreamincode.net/code/snippet1212.htm
That's a nasty example. It should be ripped down from the Internet. It's ripe for SQL Injection: http://www.mikesdotnetting.com/Article/113/Preventing-SQL-Injection-in-ASP.NET. Oh, and that's for Windows Forms, not web forms.
2wander
Member
8 Points
54 Posts
How do I execute a SQL query within a VB sub
Sep 22, 2009 06:20 PM|LINK
How do I execute a SQL query within a VB sub triggered by an event such as a page load or other event?
I want to remove out-dated records from a table before data is displayed to the user.
Here is the query I'd like to run:
DELETE FROM t_Event
WHERE (EventDate < GETDATE())
Mikesdotnett...
All-Star
155593 Points
19979 Posts
Moderator
MVP
Re: How do I execute a SQL query within a VB sub
Sep 22, 2009 06:35 PM|LINK
Rather than firing an SQL command every time someone requests a page, why not just show ones that are still current?
SELECT * From t_Event WHERE EventDate >= GetDate()
Web Pages CMS | My Site | Twitter
PeteNet
All-Star
81342 Points
11398 Posts
Re: How do I execute a SQL query within a VB sub
Sep 22, 2009 06:39 PM|LINK
* IF you still do want to clean up every time before you load data *
follow the example over here: http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlparametercollection.addwithvalue.aspx
instead of
you'll have your delete statement, and you won't need to add Parameters, as in these lines
Peter
lohith.bn
Contributor
2385 Points
403 Posts
Re: How do I execute a SQL query within a VB sub
Sep 22, 2009 06:43 PM|LINK
Check this link
http://www.dreamincode.net/code/snippet1212.htm
Mikesdotnett...
All-Star
155593 Points
19979 Posts
Moderator
MVP
Re: How do I execute a SQL query within a VB sub
Sep 22, 2009 07:03 PM|LINK
That's a nasty example. It should be ripped down from the Internet. It's ripe for SQL Injection: http://www.mikesdotnetting.com/Article/113/Preventing-SQL-Injection-in-ASP.NET. Oh, and that's for Windows Forms, not web forms.
Web Pages CMS | My Site | Twitter