Products

Solutions

Resources

Partners

Community

Blog

About

QA

Ideas Test

New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the DNN Community Forums, your preferred source of online community support for all things related to DNN.
In order to participate you must be a registered DNNizen

HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Storing ModuleID, UserID, ItemID in SQL Query?Storing ModuleID, UserID, ItemID in SQL Query?
Previous
 
Next
New Post
11/7/2007 9:45 PM
 

Assuming that your table columns for ModuleID and UserID are declared as integer (int) data type rather than one of the character data types you do NOT want to enclose these values with single quotes. So, your sql comand text should be something like:

 . . . VALUES (" & Me.ModuleID.ToString & ", " & Me.UserID.ToString & ", " & . . . etc.

HOWEVER, if you are not going to be using stored proceedures, please use parameterized queries rather than string concatenation to build your sql command.  Not only does this avoid having to know when and when not to use single quotes and # signs (for dates), it helps to avoid sql injection hacks.  PLEASE do a Google search for tutorials on SQL Parameterized Queries and consider using that technique before modifying your current code as suggested.


Bill, WESNet Designs
Team Lead - DotNetNuke Gallery Module Project (Not Actively Being Developed)
Extensions Forge Projects . . .
Current: UserExport, ContentDeJour, ePrayer, DNN NewsTicker, By Invitation
Coming Soon: FRBO-For Rent By Owner
 
New Post
11/8/2007 10:25 AM
 

Using this makes much more sense, but still having an issue with storing correctly.
Probably missing something small. Perhaps the Dim cmd As New SqlCommand is not the correct code?
What do you think it is missing?

Dim cmd As New SqlCommand
cmd.Parameters.Add(New SqlParameter("@ModuleId", Me.ModuleId.ToString))
Dim MySQL As String = "INSERT INTO TableName (ModuleID, UserID, Field1, Field2, Field3, Field4) Values (@ModuleId, 1,1,1,1,1)"
With cmd.Parameters
.Add(New SqlParameter("@ModuleId", Me.ModuleId.ToString))
End With

 
New Post
11/8/2007 1:44 PM
 

Should the Connection be included with String SQL Parameterized Queries?
I got the inserting to work, but I had to bring back some of the connection string code in order for it to insert.
When it comes to injection attacks and using SQL Parameterized Queries, is it the original connection string or complex sql query that I should be concerned with eliminating?

If I should not be using the connection string code, then the previous post's question stands.
Otherwise I tested and verified that I could store a unique value pulling from a dropdown, listbox, etc., and it would insert accordingly.
Should I be using the connection string?  or not needed?

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0Storing ModuleID, UserID, ItemID in SQL Query?Storing ModuleID, UserID, ItemID in SQL Query?


These Forums are dedicated to discussion of DNN Platform and Evoq Solutions.

For the benefit of the community and to protect the integrity of the ecosystem, please observe the following posting guidelines:

  1. No Advertising. This includes promotion of commercial and non-commercial products or services which are not directly related to DNN.
  2. No vendor trolling / poaching. If someone posts about a vendor issue, allow the vendor or other customers to respond. Any post that looks like trolling / poaching will be removed.
  3. Discussion or promotion of DNN Platform product releases under a different brand name are strictly prohibited.
  4. No Flaming or Trolling.
  5. No Profanity, Racism, or Prejudice.
  6. Site Moderators have the final word on approving / removing a thread or post or comment.
  7. English language posting only, please.
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out
What is Liquid Content?
Find Out