View Single Post
Old Apr 7th, 2008, 9:03 AM   #2
opa6x57
Hmmmm ... Is there more??
 
opa6x57's Avatar
 
Join Date: Apr 2008
Location: Post Falls, ID
Posts: 15
Rep Power: 0 opa6x57 is on a distinguished road
Re: Need help sending information from an ASP.NET form to a database

I thought I could help until I saw this...

Quote:
Originally Posted by ahlaj77 View Post
Using C# as the language in Visual Studio

I have a fairly extensive set of ASP programs which update a SQL database. The database is resident on the same server that provides the ASP pages.

Nevertheless, we established a DSN so that the connection would be smooth - which is okay in this application because the entire thing runs on a trusted network - no outside access. (You may not want to do it this way... I'm not sure.)

In the programs I have - first you define a string to contain your SQL command - using variables, this might look something like this:

vb Syntax (Toggle Plain Text)
  1. ' establish the conncetion:
  2.  
  3. Set conn = Server.CreateObject("ADODB.Connection")
  4. conn.Open "DSN=SQLAUTO"
  5.  
  6. 'begin building the SQL command string
  7. strSQL = "Update TABLE_NAME Set"
  8.  
  9. strSQL = strSQL & " COLUMN_1 = '" & (Request.Form("COLUMN1.Value")) & "'"
  10.  
  11. strSQL = strSQL & ", COLUMN_2 = '" & Cstr(Request.Form("COLUMN2.Value")) & "'"
  12.  
  13. strSQL = strSQL & ", COLUMN_3 = '" & (Request.Form("SOLUMN3.Value")) & "'"
  14.  
  15.  
  16. 'optionally add some columns to update
  17. ' based on choices made during the first post of the page...
  18.  
  19. If Request.Form("RadioBtn_Value") = "Y" Then
  20. strSQL = strSQL & ", COLUMN_4 = 'Y'"
  21. Else
  22. strSQL = strSQL & ", COLUMN_4 = 'N'"
  23. End If
  24.  
  25. If Request.Form("RadioBtn2_Value") = "Y" Then
  26. strSQL = strSQL & ", COLUMN_5 = 'Y'"
  27. Else
  28. strSQL = strSQL & ", COLUMN_5 = 'N'"
  29. End If
  30.  
  31. 'Then - add the 'where' condition
  32.  
  33. strSQL = strSQL & " Where pk_KEY = '" & variable_Key_Value & "'"
  34.  
  35. Set objCmd = Server.CreateObject("ADODB.Command")
  36.  
  37. adCmdText = 1
  38.  
  39. Set objCmd.ActiveConnection = conn
  40. objCmd.CommandText = strSQL
  41. objCmd.CommandType = adCmdText
  42. ' everything to here is preparation ... this line actually executes the QUERY
  43. objCmd.Execute
  44.  
  45. ' and don't forget to clean up after yourself.
  46. 'Close
  47. Set objCmd = Nothing
  48. conn.Close
  49. Set conn = Nothing

Maybe you can translate this VB to C# for your use - if this doesn't really answer the question .. let us know ...
__________________
Ken -
New to PFO ... but been dabbling in various versions of BASIC since highschool - circa 1973.

"Shouldn't the 'Air and Space' museum be empty?" - Dennis Miller

Last edited by opa6x57; Apr 7th, 2008 at 9:13 AM. Reason: typo in original
opa6x57 is offline   Reply With Quote