locked
How to locate ... Error code 102: Incorrect syntax near '=' RRS feed

  • Question

  • User1389508859 posted

    Hello,

    I'm getting the message "Error code 102: Incorrect syntax near '='" displayed across the top of my aspx.cs file when I run it. I have added debug=true to the top of my .aspx page, however I do not recieve any more details in respect to WHERE that syntax issue lies.

    If someone please provide me with direction on how to locate and solve this issue, it would be greatly appreciated.

    Thank you.

    Wednesday, September 25, 2013 9:33 PM

All replies

  • User839260933 posted

    Hi

    If you dont mind, Could you attach that pice of code here so that we can work it out ASAP..??

    Wednesday, September 25, 2013 11:41 PM
  • User-1635195291 posted

    Hi mallorz,

    Sorry but nothing is getting clear. Please share complete error message or paste the code so that it will be much clearer.

    Thanks,

    Jatin

    Wednesday, September 25, 2013 11:43 PM
  • User1389508859 posted
    I don't have my program available to me at the moment but I will post it when I get home tonight. Sorry for not doing that in the first place, I was just looking for advice but I understand the confusion.
    Thursday, September 26, 2013 8:48 AM
  • User1389508859 posted

    Below is my code. I have one form that loads reports into a table, the user can then choose one to edit and ID is passed to the form below. When I run the program, I get the message that the report has been updated. However, when I go to the view reports page after-the-fact the changes were not saved.

    If I run just the updateform.aspx.cs page (CTRL + F5), the form loads with the message "Error code 102: Incorrect syntax near '=' " on top ... no other information is given.

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Data.SqlClient;
    
    public partial class UpdateReport : System.Web.UI.Page
    {
    
        protected void Page_Load(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"];
    
            // Connect to Database
            SqlConnection dbConnection = new SqlConnection("Data Source=.\\SQLEXPRESS; Integrated Security=true");
    
            try
            {
                // Open database, allow alterations
                dbConnection.Open();
                dbConnection.ChangeDatabase("BugReports");
    
                // Query selected ID
                string selectBug = "SELECT * FROM softwareLog WHERE reportID =" + id;
                SqlCommand sCommand = new SqlCommand(selectBug, dbConnection);
                SqlDataReader bugReader = sCommand.ExecuteReader();
    
                if (bugReader.Read())
                {
                    // Load data according to query
                    os.Text = bugReader["typeOS"].ToString();
                    date.Text = bugReader["reportDate"].ToString();
                    hardware.Text = bugReader["hardware"].ToString();
                    occurrence.Text = bugReader["occurrence"].ToString();
                    short_des.Text = bugReader["shortDescription"].ToString();
                    long_des.Text = bugReader["longDescription"].ToString();
                    actions.Text = bugReader["actionsTaken"].ToString();
    
                    message.Text = "<p> Bug report loaded. </p>";
                    message.Text += "<p><a href='NewReport.aspx'>GO BACK</a> or <a href='Default.aspx'>GO HOME</a></p>";
                }
                else
                    message.Text = "<p> Well this is embarrassing! The data appears to be missing. </p>"; 
    
            }
            catch (SqlException ex)
            {
                // SQL Exceptions
                Response.Write("<p>Error code " + ex.Number + ": " + ex.Message + "</p>");
            }
            finally
            {
                // Close database connection
                dbConnection.Close();
            }
        }
        protected void submit_Click(object sender, EventArgs e)
        {
            string id = Request.QueryString["id"];
            updateForm.Visible = false;
    
            if (Page.IsPostBack)
            {
                Page.Validate();
                if (Page.IsValid)
                {
                    message.Visible = true;
    
                    // Create string variables
                    string _typeOS = os.SelectedItem.ToString();
                    string _reportDate = date.Text;
                    string _hardware = hardware.Text;
                    string _occurrence = occurrence.SelectedItem.ToString();
                    string _shortDes = short_des.Text;
                    string _longDes = long_des.Text;
                    string _actions = actions.Text;
    
                    // Connect to Database
                    SqlConnection dbConnection = new SqlConnection("Data Source=.\\SQLEXPRESS; Integrated Security=true");
    
                    try
                    {
                        // Open database, allow alterations
                        dbConnection.Open();
                        dbConnection.ChangeDatabase("BugReports");
                        string updateBug = "UPDATE softwareLog SET typeOS='" + _typeOS + "', reportDate='" + _reportDate + "', hardware='" + _hardware + "', occurrence='" +
                            _occurrence + "', shortDescription= '" + _shortDes + "',longDescription= '" + _longDes + "', actionsTaken= '" + _actions + "' WHERE reportID=" + id;
                        SqlCommand sCommand = new SqlCommand(updateBug, dbConnection);
                        sCommand.ExecuteNonQuery();
                        message.Text = "<p> The bug report has been updated. </p>";
                        message.Text += "<p><a href='Default.aspx'>GO HOME</a></p>";
                    }
                    catch (SqlException ex)
                    {
                        // SQL Exceptions
                        Response.Write("<p>Error code " + ex.Number + ": " + ex.Message + "</p>");
                    }
                    finally
                    {
                        // Close database connection
                        dbConnection.Close();
                    }
                }
            }
        }
    }



    Thursday, September 26, 2013 3:17 PM
  • User2103319870 posted

    Hi,

    Put a break point and check whether the string variables which you have used to assign values to your query are getting populated at runtime.

    Check the below variables

    string id = Request.QueryString["id"];
    string _typeOS = os.SelectedItem.ToString();
    string _reportDate = date.Text;
    string _hardware = hardware.Text;
    string _occurrence = occurrence.SelectedItem.ToString();
    string _shortDes = short_des.Text;
    string _longDes = long_des.Text;
    string _actions = actions.Text;



    Thursday, September 26, 2013 4:19 PM
  • User1389508859 posted

    I don't think I can do this successfully? I have to choose the ID from one form, and when I do so the corresponding form does not load in debug mode. You can see the value of the choosen ID using the breakpoint, however since the second form doesn't actually load I am unable to enter data into the other strings.

    Thursday, September 26, 2013 4:48 PM
  • User1389508859 posted

    A2H

    Hi,
    Put a break point and check whether the string variables which you have used to assign values to your query are getting populated at runtime.
    Check the below variables
    string id = Request.QueryString["id"];
    string _typeOS = os.SelectedItem.ToString();
    string _reportDate = date.Text;
    string _hardware = hardware.Text;
    string _occurrence = occurrence.SelectedItem.ToString();
    string _shortDes = short_des.Text;
    string _longDes = long_des.Text;
    string _actions = actions.Text;

    From what I can tell the string variables exist.

    I wonder if it's because two of those items (os + occurrence) are actually list boxes?

    Thursday, September 26, 2013 7:53 PM
  • User2103319870 posted

    I don't think I can do this successfully? I have to choose the ID from one form, and when I do so the corresponding form does not load in debug mode. You can see the value of the choosen ID using the breakpoint, however since the second form doesn't actually load I am unable to enter data into the other strings.

    I would suggest You to put a break point on submit button click and check values has been populated or not in variables.

    Thursday, September 26, 2013 8:44 PM
  • User1389508859 posted

    I would suggest You to put a break point on submit button click and check values has been populated or not in variables.

    Done and yes. I have an inquiry into my instructor. I was hpping to not have to go that route but maybe it'll be easier since I can send over my program.

    Thanks for your response.

    Friday, September 27, 2013 8:59 AM
  • User-1426144113 posted

    Hi,

    Could you share your project to me? That we can find the error directly.

    Thanks

    Saturday, September 28, 2013 7:41 AM