Solved

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

Posted on 2011-09-22
2
440 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
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

Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

Question has a verified solution.

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

Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

863 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

23 Experts available now in Live!

Get 1:1 Help Now