Solved

Getting an error : System.Data.SqlClient.SqlException: Incorrect syntax near '='.

Posted on 2011-09-22
2
458 Views
Last Modified: 2012-05-12
I am trying to display meta tag information that is stored in SQL database on to my product page which is built in asp.net 2.0 and C#.

All I am trying to do is if the catalogItemId of SeoText table equals to the current Product Item id then display its page title, meta tag information

I am trying to call this code on Page_Load event of the product page. but it keeps throw like below


   System.Data.SqlClient.SqlException: Incorrect syntax near '='.
   at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
   at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
   at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async)
   at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
   at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
   at mysite.product.Page_Load(Object sender, EventArgs e) in http://server/mysite/browse/product.aspx.cs:line 120


AND LINE 120 IS : SqlCmd.ExecuteNonQuery();

string query = "select MetaDescription, MetaKeywords, H1Text FROM SeoText" + "Where CatalogItemId ='" + this.CurrentProduct.ItemId + "'" ;
    SqlConnection myconnection = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDBConnection"].ConnectionString);
    SqlCommand SqlCmd = null;
    SqlCmd = new SqlCommand(query, myconnection);
    SqlCmd.Connection.Open();
    SqlCmd.ExecuteNonQuery();
    
	SqlDataAdapter ad = new SqlDataAdapter(SqlCmd);
    DataTable dt = new DataTable();
    ad.Fill(dt);
   
   
   this.Page.Title = dt.Rows[0]["MetaDescription"].ToString();
   HtmlMeta metaDesc = (HtmlMeta)Page.Header.FindControl("metaDesc");
   metaDesc.Content = dt.Rows[0]["MetaDescription"].ToString();
   HtmlMeta metaKey = (HtmlMeta)Page.Header.FindControl("metaKey");
   metaKey.Content = dt.Rows[0]["MetaKeywords"].ToString();
   Label1.Text = dt.Rows[0]["H1Text"].ToString();

Open in new window


any help is appreciated.

Thanks
0
Comment
Question by:niceoneishere
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 30

Accepted Solution

by:
Brad Howe earned 500 total points
ID: 36582497
Try this for your query.

string query = "select MetaDescription, MetaKeywords, H1Text FROM SeoText Where CatalogItemId ='" + this.CurrentProduct.ItemId + "'" ;

Cheers,
Hades666
0
 
LVL 1

Author Closing Comment

by:niceoneishere
ID: 36582557
Brilliant Thanks
0

Featured Post

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question