SQL Server :: Editing Data Error "Incorrect Syntax Near SET"
Jan 19, 2011
I am currently displaying a table on a webpage and attempting to edit it via the webpage. When I edit the data and hit update an error is produced as follows. Anyone know what the heck is causing this? Im at a lose here. Incorrect syntax near 'SET'. 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 'SET'. Source Error:
I am working with a sql server database with about 50 stored procedures. The database and stored procedureswere not created by me. The stored procedures all begin with a number in their name.
Example: 17P_Comsetter
The problem I am having is that if I try and execute the stored procedure at the command line in Query Analyzer,the query analyzer appears not to like that the stored procedure begins with a number. For example:
If I try an run the stored procedure as follows:
EXEC 17P_Comsetter
Then I get the following error message:
Msg 102, ..... Incorrect Syntax near '17'
I am using SQL server 2005. Does anyone know why I am getting this error message?
I am pinned down in this problem for sometimes and I cannot just figure out what is really I need to do to solve it. I have a store procedure that I created to get userId by email address.
ALTER PROCEDURE [dbo].[GetUserIdByEmail] @Email nvarchar(650) AS SELECT UserId FROM Users Where convert(VARCHAR(600),Email) = @Email
It works if I just run it directly, but it blow up when I run it using the code behind. Here is the error
Incorrect syntax near '.'.
It has to do with the . at the email address. For example myemail@domain.com
I'm still trying to deploy this site, but with every problem I solve, another arises. Anyways - I've set up the database at my hosting to allow remote connections, and it is running Sql Server 2005. On my development machine, I am working with Sql Server 2008.
I've installed the asp.net schema on my hosted database, and have created several users from the ASP.NET web administration interface, as well as tested that the login works. Running the application locally with the remote connection string nets the same results. However - I'm able to run my scripts and generate my tables and stored procedures without errors - but when the site is run I get the following error on all of my .aspx pages that try to access a stored procedure:
Server Error in '/' Application. Incorrect syntax near 'LoadProfileData'. Description: An unhandled exception occurred during the execution of the current web request. 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 'LoadProfileData'.
Source Error:
Line 62: adapter.SelectCommand.Parameters.Add("@ProfessionalName", SqlDbType.VarChar).Value = professionalName; Line 63: DataSet profile = new DataSet(); Line 64: adapter.Fill(profile, "Profile"); Line 65: return profile; Line 66: }
Is this a possible Sql 2005 vs 2008 issue? I'm hoping someone else has seen this issue in a similar scenario and can point me in the right direction. The server is running asp.net 2.0, 3.0 and 3.5 and IIS 7.0.
I'm using this code... What I want to do is to insert values from a table to another, but I want the user to decide from which server, database and table....
Dim cmdSelect As New System.Data.SqlClient.SqlCommand("SELECT [counts] FROM [a1_holds] WHERE (dates ='" & TextBox1.Text & "' BETWEEN from_date AND to_date) AND service ='" & lab5.Text & "' ORDER BY [id] ASC", SQLData)
i am getting this error incorrect syntax near ',' when i try to insert row in sql database through vb.net. the same command works for all tables but i get error in this.
VBNET Code: Dim cmd1 As New SqlCommand cmd1 = New SqlCommand("insert into [code]......
In SQL Query Analyzer I run this statement and I don't get anny error:
string select = "SELECT " + "aanvrager.werknemersnaam AS melder , hd_aanvragen.aanvraag_titel, " + "hd_aanvragen.aanvraag_omschrijving, hd_aanvraag_fase.fase_datum, " + "hd_melding_niveau_1.niveau_omschrijving AS 'Niveau 1', " + "hd_melding_niveau_2.niveau_omschrijving AS 'Niveau 2', " + "hd_aanvragen.outlook_id" + "FROM hd_aanvragen " + "INNER JOIN hd_meldingen ON hd_meldingen.melding_id = hd_aanvragen.melding_id " + "INNER JOIN hd_melding_niveau_1 ON hd_melding_niveau_1.niveau1_id = hd_meldingen.niveau1_id " + "INNER JOIN hd_melding_niveau_2 ON hd_melding_niveau_2.niveau2_id = hd_meldingen.niveau2_id " + "INNER JOIN hd_aanvraag_fase ON hd_aanvraag_fase.aanvraag_id = hd_aanvragen.aanvraag_id " + "INNER JOIN hd_statussen ON hd_statussen.status_id = hd_aanvraag_fase.status_id " + "INNER JOIN hd_werknemers AS oplosser ON oplosser.werknemer_Id = hd_aanvraag_fase.werknemer_Id " + "INNER JOIN hd_werknemers AS aanvrager ON aanvrager.werknemer_Id = hd_aanvragen.werknemer_Id " + "WHERE hd_statussen.status_id = 16";
But if I run this select-statement here: MyDataSource.SelectCommand = select; I get this error: Incorrect syntax near the keyword 'INNER'. 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 the keyword 'INNER'.
Incorrect syntax near '>'. I made a listview with some dropdownmenu and selectboxes to select from untill the query shows in the listview.
Now the query goes well and shows the first page of 4 rows as I wanted it.
The pager shows 5 pages and if I a want to click on the next page I get this message.
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 '>'.
<asp:SqlDataSource ID="SqlDataSource4" runat="server" ConnectionString="<%$ ConnectionStrings:AvcilarEvleri %>" SelectCommand="SELECT * FROM Tabel1 WHERE ((([Regio_Object] = @Regio_Object) AND ([Plaats_Object] = @Plaats_Object) AND ([Wijk_Object] = @Wijk_Object) AND (Prijsklasse => @Prijsklasse1) AND (Prijsklasse <= @Prijsklasse2) AND (Prijsklasse => @Prijsklasse3) AND (Prijsklasse <= @Prijsklasse4 AND (Oppervlakte_Object => @Oppervlakte_Object1) AND (Oppervlakte_Object <= @Oppervlakte_Object2)) AND ((Type_Object = @Type_Object1) OR (Type_Object = @Type_Object2) OR (Type_Object = @Type_Object3)))"> <SelectParameters> <asp:ControlParameter ControlID="DropSehir1" Name="Regio_Object" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropIl1" Name="Plaats_Object" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropDownList5" Name="Wijk_Object" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropFiyat1" Name="Prijsklasse1" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropFiyat2" Name="Prijsklasse2" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropFiyat3" Name="Prijsklasse3" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropFiyat4" Name="Prijsklasse4" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropMetre1" Name="Oppervlakte_Object1" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="DropMetre2" Name="Oppervlakte_Object2" PropertyName="SelectedValue" Type="String" /> <asp:ControlParameter ControlID="CheckBoxList1" Name="Type_Object1" PropertyName="SelectedValue" /> <asp:ControlParameter ControlID="CheckBoxList1" Name="Type_Object2" PropertyName="SelectedValue" /> <asp:ControlParameter ControlID="CheckBoxList1" Name="Type_Object3" PropertyName="SelectedValue" /> </SelectParameters> </asp:SqlDataSource>
And the code;
Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click
Panel1.Visible = False Panel4.Visible = False Panel5.Visible = False Panel6.Visible = False Panel7.Visible = False Panel8.Visible = False Panel9.Visible = False Panel10.Visible = False Panel2.Visible = True Panel3.Visible = True Dim strchklist As String = "" Dim li As ListItem For Each li In CheckBoxList1.Items If li.Selected Then strchklist += ",'" & li.Value & "'" End If Next If strchklist = "" Then Response.Write("No item Selected") End If SqlDataSource4.SelectCommand = "SELECT * FROM Tabel1 WHERE ([Regio_Object] = @Regio_Object) AND (Plaats_Object = @Plaats_Object) AND (Wijk_Object = @Wijk_Object) AND (Prijsklasse >= @Prijsklasse3) AND (Prijsklasse <= @Prijsklasse4) AND (Oppervlakte_Object >= @Oppervlakte_Object1) AND (Oppervlakte_Object <= @Oppervlakte_Object2) AND Kamers_Object IN (" & strchklist.Substring(1) & ")" SqlDataSource4.DataBind() End Sub
I am sure it has something to do with the query because and with the checkboxes.
Can someone please tell me what normally causes this error message (stack trace at bottom of this post)? I can't even tell what line or what page is producing the error.
Following are the relevant (I think) 2 code procedures...the Update command below seems to "work", because later I see that the image is updated---but I can't immediately see that: I get the above error message.
'FormView.ItemUpdating Event Protected Sub AdvertisementForm_ItemUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.FormViewUpdateEventArgs) Handles AdvertisementForm.ItemUpdating ' Get the connection string from Web.config. Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("MyDatabaseConnectionString").ToString()) ' Create a command object. Dim cmd As New SqlCommand() ' Assign the connection to the command. cmd.Connection = conn ' Set the command text ' SQL statement or the name of the stored procedure. cmd.CommandText = "UPDATE Advertisements SET UserName = @UserName, Age = @Age, Avatar = ISNULL(@Avatar, Avatar) WHERE UserId = @UserId" ' Set the command type ' CommandType.Text for ordinary SQL statements; cmd.CommandType = CommandType.Text ' Get the person ID, first name and last name from the ' EditItemTemplate of the FormView control. Dim strUserId As String = DirectCast(AdvertisementForm.Row.FindControl("UserIdTextBox"), TextBox).Text Dim strUserName As String = DirectCast(AdvertisementForm.Row.FindControl("UserNameTextBox"), TextBox).Text Dim strAge As String = DirectCast(AdvertisementForm.Row.FindControl("AgeTextBox"), TextBox).Text ' Append the parameters to the SqlCommand and set values. cmd.Parameters.Add("@UserId", SqlDbType.UniqueIdentifier).Value = Guid.Parse(strUserId) cmd.Parameters.Add("@UserName", SqlDbType.NChar).Value = strUserName cmd.Parameters.Add("@Age", SqlDbType.NChar).Value = strAge ' Find the FileUpload control in the EditItemTemplate of ' the FormView control. Dim uploadAvatar As FileUpload = DirectCast(AdvertisementForm.FindControl("uploadAvatar"), FileUpload) If uploadAvatar.HasFile Then ' Append the Picture parameter to the SqlCommand. ' If a picture is specified, set the parameter with ' the value of bytes in the specified picture file. cmd.Parameters.Add("@Avatar", SqlDbType.VarBinary).Value = uploadAvatar.FileBytes Else ' Append the Picture parameter to the SqlCommand. ' If no picture is specified, set the parameter's ' value to NULL. cmd.Parameters.Add("@Avatar", SqlDbType.VarBinary).Value = DBNull.Value End If ' Open the connection. conn.Open() ' Execute the command. cmd.ExecuteNonQuery() End Using ' Switch FormView control to the ReadOnly display mode. AdvertisementForm.ChangeMode(FormViewMode.ReadOnly) ' Rebind the FormView control to show data after updating. BindFormView() End Sub Private Sub BindFormView() ' Get the connection string from Web.config. Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("MyDatabaseConnectionString").ToString()) ' Create a DataSet object. Dim dsPerson As New DataSet(). ' Create a SELECT query. Dim strSelectCmd As String = "SELECT UserId, Avatar FROM Advertisements" ' Create a SqlDataAdapter object Dim da As New SqlDataAdapter(strSelectCmd, conn) ' Open the connection conn.Open() ' Fill the DataTable named "Advertisements" in DataSet with the rows ' returned by the query. da.Fill(dsAdvertisements, "Advertisements") Dim dsAdvertisements As DataSet = New DataSet() ' Bind the FormView control. AdvertisementForm.DataBind() End Using End Sub Server Error in '/www.mywebsite.com' Application. Incorrect syntax near ','. [Code].... Stack Trace: [Code]....
I'm still trying to deploy this site, but with every problem I solve, another arises. Anyways - I've set up the database at my hosting to allow remote connections, and it is running Sql Server 2005. On my development machine, I am working with Sql Server 2008.
I've installed the asp.net schema on my hosted database, and have created several users from the ASP.NET web administration interface, as well as tested that the login works. Running the application locally with the remote connection string nets the same results. However - I'm able to run my scripts and generate my tables and stored procedures without errors - but when the site is run I get the following error on all of my .aspx pages that try to access a stored procedure:
Server Error in '/' Application. Incorrect syntax near 'LoadProfileData'. Description: An unhandled exception occurred during the execution of the current web request. 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 'LoadProfileData'.
Source Error:
Line 62: adapter.SelectCommand.Parameters.Add("@ProfessionalName", SqlDbType.VarChar).Value = professionalName; Line 63: DataSet profile = new DataSet(); Line 64: adapter.Fill(profile, "Profile"); Line 65: return profile; Line 66: }
Is this a possible Sql 2005 vs 2008 issue? I'm hoping someone else has seen this issue in a similar scenario and can point me in the right direction. The server is running asp.net 2.0, 3.0 and 3.5 and IIS 7.0.
Stored Procedure:
Drop procedure CreateDefaultProfile GO Create procedure CreateDefaultProfile(@UserName varchar(256)) as declare @ProfessionalID uniqueidentifier
I have a UDF called Split which accepts a comma separated list and returns a table variable splitting the values in a row. So for ex if I call the function
Select * From dbo.Split('100,287,312', ',')
The output of this query will be
ID-----Value 1------100 2------287 3------312
Now I am trying to use cross apply to return each row for each csv but I am getting an error Line 3: Incorrect syntax near 'apply'.
Here is my query
select c.course_id, c.course_title, b.* from course c cross apply dbo.[Split](c.foreign_lang_equiv_course_id, ',') As b
I have already stored value of author id in list item value while page loads. but when I change index of drop down list to view author information error is shown. I tried to debug using check points and it seems Sqlreader isn't reading database second time.
i am making a shopping cart and i am receiving this error when tryin to add a product to an order. Incorrect syntax near the keyword 'Order'. 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 the keyword 'Order'. Source Error:
[Code]....
Source File: c:UsersPerk-OnDocumentsVisual Studio 2008WebSitesestApp_CodeCart.cs Line: 69 Stack Trace: