Hey everyone. I received this server error and I can't figure out where the trouble is:
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 '='.
Source Error:
Line 24: System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(selectSql, connectionString); Line 25: System.Data.DataSet ds = new System.Data.DataSet(); Line 26: da.Fill(ds, "DEL_PROGRAM"); Line 27: System.Data.DataTableCollection dtc = ds.Tables; Line 28: System.Data.DataTable dt = dtc[0];
Source File: ***** Line: 26
My code is here:
protected void Page_Load(object sender, EventArgs e)
{
// Opens connection to the database
string connectionString = ConfigurationManager.ConnectionStrings["Ektron.DbConnection"].ToString();
// Defines query
string selectSql;
selectSql = "SELECT ProgramName FROM DEL_PROGRAM WHERE College == 'AS'";
// Returns query results to data table
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(selectSql, connectionString);
System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds, "DEL_PROGRAM");
System.Data.DataTableCollection dtc = ds.Tables;
System.Data.DataTable dt = dtc[0];
foreach (System.Data.DataRow dr in dt.Rows)
{
lblContent1.Text += dr["ProgramName"].ToString();
}
}
Can anyone help? I'm not sure '=' the error is referring to.
hi this error came beacuse you have write this ,, (the variable in which ur are getting data.) in the source page of the relevant page e.g (ur source page of the masterpage.) hope this help
hi this error came beacuse you have NOT wrote this code as ,, (the variable in which ur are getting data.) in the source page of the relevant page e.g (ur source page of the masterpage.) hope this help
Member
146 Points
139 Posts
System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Oct 25, 2007 11:55 AM|bhuber7|LINK
Hey everyone. I received this server error and I can't figure out where the trouble is:
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 '='.
Source Error:
Source File: ***** Line: 26
My code is here:
protected void Page_Load(object sender, EventArgs e)
{
// Opens connection to the database
string connectionString = ConfigurationManager.ConnectionStrings["Ektron.DbConnection"].ToString();
// Defines query
string selectSql;
selectSql = "SELECT ProgramName FROM DEL_PROGRAM WHERE College == 'AS'";
// Returns query results to data table
System.Data.SqlClient.SqlDataAdapter da = new System.Data.SqlClient.SqlDataAdapter(selectSql, connectionString);
System.Data.DataSet ds = new System.Data.DataSet();
da.Fill(ds, "DEL_PROGRAM");
System.Data.DataTableCollection dtc = ds.Tables;
System.Data.DataTable dt = dtc[0];
foreach (System.Data.DataRow dr in dt.Rows)
{
lblContent1.Text += dr["ProgramName"].ToString();
}
}
Can anyone help? I'm not sure '=' the error is referring to.
Thanks!
Member
622 Points
180 Posts
Re: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Oct 25, 2007 12:09 PM|dhanabalanr|LINK
Hey
look at your sql select query. it has two equal(=) sign. that is the error
Hope it helps
Dhana
Dont forget to mark as answer if my reply helped you...
Member
146 Points
139 Posts
Re: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Oct 25, 2007 02:27 PM|bhuber7|LINK
Yup, that was the problem. Thanks!
None
0 Points
2 Posts
Re: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Feb 07, 2009 12:47 PM|rizwanocp63|LINK
None
0 Points
2 Posts
Re: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Feb 07, 2009 12:49 PM|rizwanocp63|LINK
None
0 Points
2 Posts
Re: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Feb 05, 2010 12:49 PM|tozogabee|LINK
HI Everybody.
I have got similar problem.
I use parameter query.When I click the button,I'll get an exception:Incorrect syntax near '='.
this is my source code:
<div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> protected void Button1_Click(object sender, EventArgs e)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> lblName.Text = "";</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> SqlConnection conn;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> string strSELECTWithParameters;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> SqlCommand cmd;</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> string strConn = ConfigurationSettings.AppSettings["CS"];</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> conn = new SqlConnection(strConn);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> strSELECTWithParameters = "SELECT Name FROM kuncsaft" + "WHERE Age=@Age AND Weight=@Weight";</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> cmd = new SqlCommand(strSELECTWithParameters, conn);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> cmd.Parameters.Add("@Age",age.Text);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> cmd.Parameters.Add("@Weight",weight.Text);</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> conn.Open();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> try</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> lblName.Text = cmd.ExecuteScalar().ToString();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> }</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> catch (Exception exc)</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> {</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> lblName.Text = "<font color='red'>"+exc.Message+"</font>";</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> }</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"></div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> conn.Close();</div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> </div> <div style="position: absolute; left: -10000px; top: 0px; width: 1px; height: 1px; overflow-x: hidden; overflow-y: hidden;" id="_mcePaste"> }</div>protected void Button1_Click(object sender, EventArgs e)
{
lblName.Text = "";
SqlConnection conn;
string strSELECTWithParameters;
SqlCommand cmd;
string strConn = ConfigurationSettings.AppSettings["CS"];
conn = new SqlConnection(strConn);
strSELECTWithParameters = "SELECT Name FROM kuncsaft" + "WHERE Age=@Age AND Weight=@Weight";
cmd = new SqlCommand(strSELECTWithParameters, conn);
cmd.Parameters.Add("@Age",age.Text);
cmd.Parameters.Add("@Weight",weight.Text);
conn.Open();
try
{
lblName.Text = cmd.ExecuteScalar().ToString();
}
catch (Exception exc)
{
lblName.Text = "<font color='red'>"+exc.Message+"</font>";
}
conn.Close();
} protected void Button1_Click(object sender, EventArgs e)
{
lblName.Text = "";
SqlConnection conn;
string strSELECTWithParameters;
SqlCommand cmd;
string strConn = ConfigurationSettings.AppSettings["CS"];
conn = new SqlConnection(strConn);
strSELECTWithParameters = "SELECT Name FROM kuncsaft" + "WHERE Age=@Age AND Weight=@Weight";
cmd = new SqlCommand(strSELECTWithParameters, conn);
cmd.Parameters.Add("@Age",age.Text);
cmd.Parameters.Add("@Weight",weight.Text);
conn.Open();
try
{
lblName.Text = cmd.ExecuteScalar().ToString();
}
catch (Exception exc)
{
lblName.Text = "<font color='red'>"+exc.Message+"</font>";
}
conn.Close();
}
Please help me.Thanks
Member
146 Points
139 Posts
Re: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Feb 05, 2010 01:09 PM|bhuber7|LINK
You may have to use:
None
0 Points
2 Posts
Re: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Feb 05, 2010 02:33 PM|tozogabee|LINK
Thanks for your quick answer,but the problem is even same.
The problem exist,when I write the both of TextBoxes as well.
What am I doing?
I get nervous for this exception.
Thanks in advance.
None
0 Points
3 Posts
Re: System.Data.SqlClient.SqlException: Incorrect syntax near '='.
Jan 21, 2014 03:28 PM|Andeta7|LINK
Hey guys please can you help me to fix that, iv got the same problem
im gettin this error : Incorrect syntax near 'ListBus' .
Its refering to sda.Fill(ds,"ListBus")
in the code below
thanks in advance