Wednesday, March 7, 2012

HELP - insert record SQLExpress database

Hi! i ask you some help..I should build a simple INSERT FORM in a SQLExpress database..

but clicking ADD I have this error :

Incorrect syntax near '='.

Description:An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details:System.Data.SqlClient.SqlException: Incorrect syntax near '='.

Source Error:

Line 38: conDatabase.Open()Line 39:Line 40: cmdInsert.ExecuteNonQuery()Line 41: Line 42: conDatabase.Close()

some solution?

the source code:

<%

@.PageLanguage="VB"Debug="true"%>

<%

@.ImportNamespace="System.Data"%>

<%

@.ImportNamespace="System.Data.SqlClient"%>

<!

DOCTYPEhtmlPUBLIC"-//W3C//DTD XHTML 1.0 Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<

scriptrunat="server">Sub Button_clic(ByVal sAsObject,ByVal eAs EventArgs)Dim conDatabaseAs SqlConnectionDim strInsertAsStringDim cmdInsertAs SqlCommandDim myExecuteQueryAsStringDim myExecuteCmdAs SqlCommand

conDatabase =

New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Inetpub\wwwroot\tesi\App_Data\database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True")

strInsert =

"Insert pubblicazioni (Nome, Cognome, Titolo) Values = (@.Nome, @.Cognome, @.Titolo) "

cmdInsert =

New SqlCommand(strInsert, conDatabase)

cmdInsert.Parameters.Add(

"@.Nome", txtNome.Text)

cmdInsert.Parameters.Add(

"@.Cognome", txtCognome.Text)

cmdInsert.Parameters.Add(

"@.Titolo", txtTitolo.Text)

conDatabase.Open()

cmdInsert.ExecuteNonQuery()

conDatabase.Close()

Response.Redirect(

"success.html")EndSub

</

script>

<

htmlxmlns="http://www.w3.org/1999/xhtml">

<

headid="Head1"runat="server"><title>iNSERIMENTO</title><LINKhref="mauro.css"rel=stylesheet>

<

scripttype="text/javascript"language="javascript">

<!--

function

popopen(){

window.open(

"upload/upload.aspx","name"," toolbar=no,directories=no,menubar=no,width=300,height=300,top=100,left=150,resizable=no,scrollbars=yes");

}

// -->

</

script>

</

head>

<

bodybgcolor="#DFE5F2"style="font-size: 12pt"><formid="form1"runat="server"><div> <asp:LabelID="Label1"runat="server"BackColor="#8080FF"BorderColor="Black"ForeColor="Black"Height="29px"Text="FORM INSERIMENTO DOCUMENTO"Width="371px"Font-Bold="True"Font-Names="Verdana"Font-Size="14pt"Font-Underline="True"></asp:Label><br/><br/><br/><B><spanstyle="font-family: Verdana">NOME </span></B><asp:TextBoxID="txtNome"runat="server"></asp:TextBox> <B><spanstyle="font-family: Verdana">COGNOME </span></B><asp:TextBoxID="txtCognome"runat="server"></asp:TextBox><br/><br/><B><spanstyle="font-family: Verdana">TITOLO </span></B><asp:TextBoxID="txtTitolo"runat="server"></asp:TextBox><br/><br/>

<ahref="javascript:popopen()">CARICA DOCUMENTO</a><br/><br/>

<asp:ButtonID="Button1"runat="server"OnClick="Button_Clic"Text="ADD"Font-Bold="True"Font-Names="Verdana"Font-Size="12pt"Width="160px"/></div><br><br></form>

</

body>

</

html>Remove the "=" sign in the INSERT statement.|||

ndinakar:

Remove the "=" sign in the INSERT statement.

damn!ehehehe ; ) thanks you....

No comments:

Post a Comment