CodeCharge Studio
search Register Login  

Web Reports

Visually create Web Reports in PHP, ASP, .NET, Java, Perl and ColdFusion.
CodeCharge.com

YesSoftware Forums -> CodeCharge Studio -> .NET

 Code to execute SQL statement in .NET(VB)

Print topic Send  topic

Author Message
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
View profile  Send private message
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
View profile  Send private message
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
View profile  Send private message

Add new topic Subscribe to topic   


These are Community Forums for users to exchange information.
If you would like to obtain technical product help please visit http://support.yessoftware.com.

Web Database

Join thousands of Web developers who build Web applications with minimal coding.
CodeCharge.com

Home   |    Search   |    Members   |    Register   |    Login


Powered by UltraApps Forum created with CodeCharge Studio
Copyright © 2003-2004 by UltraApps.com  and YesSoftware, Inc.