andrewi
Posts: 162
|
Posted: 01/04/2005, 3:50 PM |
|
Can anyone provide a snippet of code for executing an SQL statement (or calling a stored procedure) to use in one of the page events - such as BeforeUpdate.
There seem to be plenty of examples here and in help files for ASP & PHP, but none that I've found for .NET.
For example, this is what I might use in an event in ASP:
Set aiConn = New clsDBFasthosts
aiConn.Open
strSQL = "INSERT INTO dbo.tblClient (c_LastName, c_FirstName, c_Title) " & _
"VALUES (" & _
aiConn.ToSQL(Record1.c_LastName.Value, ccsText) & " , " & _
aiConn.ToSQL(Record1.c_FirstName.Value, ccsText) & ", " & _
aiConn.ToSQL(Record1.c_Title.Value, ccsText) & ")"
aiConn.Execute(strSQL)
But what would the equivalent be for .NET ?
Thanks
Andrew
|
|
|
mrachow
Posts: 509
|
Posted: 01/05/2005, 12:01 AM |
|
Please have a look at the Component Reference (PDF).
There are a lot of examples and usually the code is given for all scripting languages.
For your special case have a look at the paragraph Dynamically Modify the SQL Statement
_________________
Best regards,
Michael |
|
|
andrewi
Posts: 162
|
Posted: 01/05/2005, 1:17 AM |
|
Great. And the following section Working with Databases - Execute Custom SQL has the code I think I need:
Dim Request As HttpRequest = HttpContext.Current.Request
Dim NewDao As DataAccessObject = Settings.Connection1DataAccessObject
Dim Sql As String = "INSERT INTO report (report_task_id,report_creator) " & _
"VALUES ("& NewDao.ToSql(Request.QueryString("task_id"),FieldType._Integer) &","& _
NewDao.ToSql(DBUtility.UserId.ToString(),FieldType._Integer) &")"
NewDao.RunSql(Sql)
Both are in the normal helpfile too after all. Thanks for the pointer.
Rgds
Andrew
|
|
|
|