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" /> <br />
<br />
<asp:Label ID="Label1" runat="server" Text="Non de l'image" Width="107px"></asp:Label>
<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>