SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 23rd, 2005, 01:31 PM
ehsanking ehsanking is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 207 ehsanking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 3 m 51 sec
Reputation Power: 4
What is wrong with this insert statement?

well i got an aspx page that supposed to insert some data in sql server db and it generates this sql statment but it give error in writing to sql server 2000:

Server Error in '/asp' Application.
--------------------------------------------------------------------------------

The name 'me' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.
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: The name 'me' is not permitted in this context. Only constants, expressions, or variables allowed here. Column names are not permitted.

Note: me is the value for name feild that i typed in the form

I be happy if some one help me how to correct it. Thanks
Here is the corde part that supposed to generate the insert statment :


<%@ Page Language="VB" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SQLClient" %>
<script Language="VB" Option="Explicit" runat="server">

Sub Page_Load(Src as object, E as EventArgs)
' Hide Insert Confirmation Message
pnlConfirm.Visible = False
End Sub

Sub btnSave_OnClick(Src as object, E as EventArgs)
Dim dtDateTimeInput as DateTime
Dim strSQL as String
Dim objConnection as SqlConnection
Dim objCommand as SqlCommand

If Page.IsValid Then
' Save the Data to the DB

' Check Values - The validators do most of this, but I was
' too lazy to come up with (ie. write) a custom validator for
' the Date/Time field.
Try
validtxtDateTimeField.Text = ""
dtDateTimeInput = CDate(txtDateTimeField.Text)
Catch Exp As Exception
'Response.Write(Exp)
validtxtDateTimeField.Text = "Please enter a valid Date/Time value."

Exit Sub
End Try

' Build our SQL String
strSQL = ""
strSQL = strSQL & "INSERT INTO PLAYERS "
strSQL = strSQL & "(PLAYERNO,NAME,INIIALS,BIRTH_DATE,SEX,JOINED,STREE T,HOUSENO,POSTCODE,TOWN,PHONENO,LEAGUENO) " & vbCrLf
strSQL = strSQL & "VALUES ("
strSQL = strSQL & "'" & txtIntegerField1.Text & "'"
strSQL = strSQL & ", "
strSQL = strSQL & txtTextField1.Text
strSQL = strSQL & ", "
strSQL = strSQL & "'" & txtTextField2.Text & "'"
strSQL = strSQL & ", "
strSQL = strSQL & txtDateTimeField.Text
strSQL = strSQL & ", "
strSQL = strSQL & "'" & txtTextField3.Text & "'"
strSQL = strSQL & ", "
strSQL = strSQL & txtIntegerField2.Text
strSQL = strSQL & ", "
strSQL = strSQL & "'" & txtTextField4.Text & "'"
strSQL = strSQL & ", "
strSQL = strSQL & txtIntegerField3.Text
strSQL = strSQL & ", "
strSQL = strSQL & "'" & txtIntegerField4.Text & "'"
strSQL = strSQL & ", "
strSQL = strSQL & txtTextField5.Text
strSQL = strSQL & ", "
strSQL = strSQL & "'" & txtIntegerField5.Text & "'"
strSQL = strSQL & ", "
strSQL = strSQL & txtIntegerField6.Text
'strSQL = strSQL & ", "

'strSQL = strSQL & "'" & dtDateTimeInput & "'"
strSQL = strSQL & ");"
Response.Write(strSQL)

' Set up our connection.
objConnection = New SqlConnection("Data Source=(local);" _
& "Initial Catalog=teniss2;User Id=web;Password=web;" _
& "Connect Timeout=15;Network Library=dbmssocn;")

objCommand = New SqlCommand(strSQL, objConnection)

objCommand.Connection.Open()
objCommand.ExecuteNonQuery()
objCommand.Connection.Close()

' Display Confirmation Message:
lblSQL.Text = strSQL
pnlConfirm.Visible = True
End If
End Sub

</script>

Reply With Quote
  #2  
Old April 23rd, 2005, 01:32 PM
ehsanking ehsanking is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 207 ehsanking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 h 3 m 51 sec
Reputation Power: 4
Here is the rest of the code :

<html>
<head>
<title>ASP.NET Form to Database Sample from ASP 101</title>
</head>
<body>

<form runat="server">

<table border="0">
<tr>
<td align="right"><strong>Player Number Field:</strong></td>
<td align="left">
<asp:TextBox id="txtIntegerField1" runat="server" />
<asp:RequiredFieldValidator id="validtxtIntegerFieldReq1"
ControlToValidate="txtIntegerField1"
Display="Dynamic"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
<asp:RangeValidator id="validtxtIntegerFieldRange1"
ControlToValidate="txtIntegerField1"
Display="Dynamic"
MinimumValue="-32768"
MaximumValue="32767"
Type="Integer"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
</td>
</tr>
<tr>
<td align="right"><strong>NAME Text Field:</strong></td>
<td align="left">
<asp:TextBox id="txtTextField1" maxlength="10" runat="server" />
<asp:RequiredFieldValidator id="validtxtTextField1"
ControlToValidate="txtTextField1"
Display="Dynamic"
Text="Please enter some text."
ForeColor="#FF0000"
runat="server"
/>
</asp:RequiredFieldValidator>
</td>
</tr>

<tr>
<td align="right"><strong>INITIALS Text Field:</strong></td>
<td align="left">
<asp:TextBox id="txtTextField2" maxlength="10" runat="server" />
<asp:RequiredFieldValidator id="validtxtTextField2"
ControlToValidate="txtTextField2"
Display="Dynamic"
Text="Please enter some text."
ForeColor="#FF0000"
runat="server"
/>
</asp:RequiredFieldValidator>
</td>
</tr>

<tr>
<td align="right"><strong>BIRTH_DATE Date/Time Field:</strong></td>
<td align="left">
<asp:TextBox id="txtDateTimeField" runat="server" />
<asp:Label id="validtxtDateTimeField"
ForeColor="#FF0000"
runat="server"
/>
</td>
</tr>


<tr>
<td align="right"><strong>SEX Text Field:</strong></td>
<td align="left">
<asp:TextBox id="txtTextField3" maxlength="10" runat="server" />
<asp:RequiredFieldValidator id="validtxtTextField3"
ControlToValidate="txtTextField3"
Display="Dynamic"
Text="Please enter some text."
ForeColor="#FF0000"
runat="server"
/>
</asp:RequiredFieldValidator>
</td>
</tr>

<tr>
<td align="right"><strong>JOINED Field:</strong></td>
<td align="left">
<asp:TextBox id="txtIntegerField2" runat="server" />
<asp:RequiredFieldValidator id="validtxtIntegerFieldReq2"
ControlToValidate="txtIntegerField2"
Display="Dynamic"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
<asp:RangeValidator id="validtxtIntegerFieldRange2"
ControlToValidate="txtIntegerField2"
Display="Dynamic"
MinimumValue="-32768"
MaximumValue="32767"
Type="Integer"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
</td>
</tr>

<tr>
<td align="right"><strong>STREET Text Field:</strong></td>
<td align="left">
<asp:TextBox id="txtTextField4" maxlength="10" runat="server" />
<asp:RequiredFieldValidator id="validtxtTextField4"
ControlToValidate="txtTextField4"
Display="Dynamic"
Text="Please enter some text."
ForeColor="#FF0000"
runat="server"
/>
</asp:RequiredFieldValidator>
</td>
</tr>

<tr>
<td align="right"><strong>HOUSENO Field:</strong></td>
<td align="left">
<asp:TextBox id="txtIntegerField3" runat="server" />
<asp:RequiredFieldValidator id="validtxtIntegerFieldReq3"
ControlToValidate="txtIntegerField3"
Display="Dynamic"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
<asp:RangeValidator id="validtxtIntegerFieldRange3"
ControlToValidate="txtIntegerField3"
Display="Dynamic"
MinimumValue="-32768"
MaximumValue="32767"
Type="Integer"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
</td>
</tr>


<tr>
<td align="right"><strong>POSTCODE Field:</strong></td>
<td align="left">
<asp:TextBox id="txtIntegerField4" runat="server" />
<asp:RequiredFieldValidator id="validtxtIntegerFieldReq4"
ControlToValidate="txtIntegerField4"
Display="Dynamic"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
<asp:RangeValidator id="validtxtIntegerFieldRange4"
ControlToValidate="txtIntegerField4"
Display="Dynamic"
MinimumValue="-32768"
MaximumValue="32767"
Type="Integer"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
</td>
</tr>
<tr>
<td align="right"><strong>Town Text Field:</strong></td>
<td align="left">
<asp:TextBox id="txtTextField5" maxlength="10" runat="server" />
<asp:RequiredFieldValidator id="validtxtTextField5"
ControlToValidate="txtTextField5"
Display="Dynamic"
Text="Please enter some text."
ForeColor="#FF0000"
runat="server"
/>
</asp:RequiredFieldValidator>
</td>
</tr>

<tr>
<td align="right"><strong>PHONENO Field:</strong></td>
<td align="left">
<asp:TextBox id="txtIntegerField5" runat="server" />
<asp:RequiredFieldValidator id="validtxtIntegerFieldReq5"
ControlToValidate="txtIntegerField5"
Display="Dynamic"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
<asp:RangeValidator id="validtxtIntegerFieldRange5"
ControlToValidate="txtIntegerField5"
Display="Dynamic"
MinimumValue="-32768"
MaximumValue="32767"
Type="Integer"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
</td>
</tr>
<tr>
<td align="right"><strong>LEAGUENO Field:</strong></td>
<td align="left">
<asp:TextBox id="txtIntegerField6" runat="server" />
<asp:RequiredFieldValidator id="validtxtIntegerFieldReq6"
ControlToValidate="txtIntegerField6"
Display="Dynamic"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
<asp:RangeValidator id="validtxtIntegerFieldRange6"
ControlToValidate="txtIntegerField6"
Display="Dynamic"
MinimumValue="-32768"
MaximumValue="32767"
Type="Integer"
Text="Please enter a number between -32768 and 32767."
ForeColor="#FF0000"
runat="server"
/>
</td>
</tr>
<tr>
<td>&nbsp;</td>
<td><asp:Button id="btnSave" runat="server"
OnClick="btnSave_OnClick"
Text="Save To Database"
/>
</td>
</tr>
</table>

<asp:Panel id="pnlConfirm" runat="server">
<h2>Thanks for submitting your information to us!</h2>

<p>
<strong>The resulting SQL statement was:</strong>
<pre><asp:Label id="lblSQL" runat="server" /></pre>
</p>
</asp:Panel>

<p>

<a href="db_count.aspx">next page</a>.
</p>

</form>

</body>
</html>

Reply With Quote
  #3  
Old April 24th, 2005, 12:24 AM
lewy's Avatar
lewy lewy is offline
Alter Ego Wizard
ASP Free Specialist (4000 - 4499 posts)
 
Join Date: Jun 2004
Location: Edinburg Tx
Posts: 4,385 lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)lewy User rank is General 9th Grade (Above 100000 Reputation Level)  Folding Points: 1009 Folding Title: Novice Folder
Time spent in forums: 1 Month 1 Week 2 Days 52 m 30 sec
Reputation Power: 1561
Try this as your btnSave_OnClick
Code:
Sub btnSave_OnClick(s as object, e as EventArgs)  
        Try
              Dim objConnection as SqlConnection
              Dim objCommand as SqlCommand
             
              'You may want to check your connection string
              'proper use of sql server connection is as follows:
              objConnection = New SqlConnection("Server=YOURSERVERNAME\NETSDK; " & _
 	 			 "Database=YOURDATABASENAME;" & _
 			 	 "User ID=YOURDBUSERNAME;Password=YOURDBPASSWORD")
            
              objCommand = New SqlCommand("INSERT INTO PLAYERS (PLAYERNO,NAME,INITIALS,BIRTH_DATE, " & _
 				 "SEX,JOINED,STREET,HOUSENO,POSTCODE,TOWN,PHONENO,LE  AGUENO) " & _
 				 "VALUES(@PLAYERNO,@NAME,@INITIALS,@BIRTH_DATE,@SEX,  @JOINED, " & _
 				 "@STREET,@HOUSENO,@POSTCODE,@TOWN,@PHONENO,@LEAGUEN  O, objConnection)
            
              objCommand.Parameters.Add(@PLAYERNO, txtIntegerField1.Text)
              objCommand.Parameters.Add(@NAME, txtTextField1.Text)
              objCommand.Parameters.Add(@INITIALS, txtTextField2.Text)
              objCommand.Parameters.Add(@BIRTH_DATE, txtDateTimeField.Text)
              objCommand.Parameters.Add(@SEX, txtTextField3.Text)
              objCommand.Parameters.Add(@JOINED, txtIntegerField2.Text)
              objCommand.Parameters.Add(@STREET, txtTextField4.Text)
              objCommand.Parameters.Add(@HOUSENO, txtIntegerField3.Text)
              objCommand.Parameters.Add(@POSTCODE, txtIntegerField4.Text)
              objCommand.Parameters.Add(@TOWN, txtTextField5.Text)
              objCommand.Parameters.Add(@PHONENO, txtIntegerField5.Text)
              objCommand.Parameters.Add(@LEAGUENO, txtIntegerField6.Text)
            
              objConnection.Open()
              objCommand.ExecuteNonQuery()
              objConnection.Close()
     Catch objException as Exception
        Response.Write("Error Message" & objException.Message & "<br />")
        Response.Write("StackTrace: " & objException.StackTrace & "<br />")
     End Try
  End Sub
__________________
................... ASCII and ye shall receive ..................
Knowledge is the only resource on earth that multiplies when shared


Support the Shemzilla Project
Powered by C#

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > What is wrong with this insert statement?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT