Solved

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

Posted on 2011-09-22
2
437 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
2 Comments
 
LVL 30

Accepted Solution

by:
Brad Howe earned 500 total points
Comment Utility
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
Comment Utility
Brilliant Thanks
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

771 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now