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.0error sql syntaxeerror sql syntaxe
Previous
 
Next
New Post
3/19/2009 10:42 PM
 

When I try to create a module allow me to upload an image within an Uploads folder and input some information about this image in DataBase exactly in the table called Images (ImageID, ImageName, ImageDesc, ImagePath) I got an SQL error syntax located in the name variable please help me

 

 

---------------------------------------------------------------------------------------this is the code behind ------------------------------------------------------------------------------------


Imports DotNetNuke
Imports System.Web.UI
Imports System.Collections.Generic
Imports System.Reflection
Imports DotNetNuke.Security.PortalSecurity


Partial Class DesktopModules_Images_viewImages
    Inherits Entities.Modules.PortalModuleBase

    Dim myConnection As SqlConnection = New SqlConnection("server=ISITC-A31266378;uid=dnnuser40;pwd=1311984;database=DotNetNuke40")

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click

       
        Dim name As String = TextBoxImName.Text
        Dim path As String = FileUpload1.PostedFile.FileName
        Dim description As String = FileUpload1.PostedFile.ContentLength

        If FileUpload1.HasFile Then

            Try
                FileUpload1.SaveAs("C:\DotNetNuke40\Uploads\" & FileUpload1.FileName)
                LblName.Text = "File name: " & FileUpload1.PostedFile.FileName
                LblSize.Text = "File Size: " & FileUpload1.PostedFile.ContentLength & " kb"
                LblContent.Text = "Content type: " & FileUpload1.PostedFile.ContentType
            Catch ex As Exception
                LblName.Text = "ERROR: " & ex.Message.ToString()


            End Try
        Else
            LblName.Text = "You have not specified a file."
            LblSize.Text = ""
            LblContent.Text = ""
        End If
        InsertData(name, description, path)


    End Sub


    Private Sub InsertData(ByVal name As String, ByVal description As String, ByVal path As String)
        Dim ra As Integer
        Dim myConnection As SqlConnection = New SqlConnection("server=ISITC-A31266378;uid=dnnuser40;pwd=1311984;database=DotNetNuke40")
        'you need to provide password for sql server
        myConnection.Open()
        Dim myCommand As SqlCommand = New SqlCommand("Insert into Images values " & name & "," & description & "," & path, myConnection)
        Response.Write(myCommand.ToString)
        ra = myCommand.ExecuteNonQuery()
        'Since no value is returned we use ExecuteNonQuery
        Response.Write("Records Inserted" & ra)
        myConnection.Close()

    End Sub

End Class

 

 

-----------------------------------------------------------------------------------------this is the ascx control------------------------------------------------------------------------------

 

<%@ Control Language="VB" AutoEventWireup="false" CodeFile="ViewImages.ascx.vb" Inherits="DesktopModules_Images_viewImages" %>

<asp:FileUpload ID="FileUpload1" runat="server" /><br />

<asp:Button ID="Button1" runat="server" OnClick="Button1_Click"
         Text="Upload File" />&nbsp;<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Non de l'image" Width="107px"></asp:Label>&nbsp;
 <asp:TextBox ID="TextBoxImName" runat="server"></asp:TextBox><br />
<br />
<asp:Label ID="LblName" runat="server" Width="699px"></asp:Label>

<br />
<asp:Label ID="LblSize" runat="server" Width="698px"></asp:Label><br />
<asp:Label ID="LblContent" runat="server" Width="698px"></asp:Label>



 
New Post
3/20/2009 1:39 AM
 

najmeddine wrote

 

Dim myCommand As SqlCommand = New SqlCommand("Insert into Images values " & name & "," & description & "," & path, myConnection)

It looks like your sql insert command isn't formed correctly. Actually, looking at MSDN it looks like that "should" work depending on the actual values getting stored to the database. I'd really recommend writing stored procedures or using LINQ in addition to using one of the many development guides Google can locate for DotNetNuke. This will really simplify the development process and any errors you might encounter. I'd also recommend looking at the code endeavor templates to help simplify the packaging of your module.

 
Previous
 
Next
HomeHomeArchived Discus...Archived Discus...Developing Under Previous Versions of .NETDeveloping Under Previous Versions of .NETASP.Net 2.0ASP.Net 2.0error sql syntaxeerror sql syntaxe


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