syntax error near the where condition with dataset
I'm wondering why am i receiving an error on my where condition. I have to
use 2 SQL connections in order to do a paging and sorting for my gridview.
I have checked my SQL code multiple times and didnt find any where
condition error
using (var connAdd = new
SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString))
{
connAdd.Open();
DataSet ds = new DataSet();
var sql = "SELECT memberreportid, typeofcrime, crdatetime,
address, incidentdate, incidenttime, property, victim,
suspect, detail, propertydetail, suspectdetail from
memberreport where assignto = 'unassign'";
using (var cmdAdd = new SqlDataAdapter(sql, connAdd))
{
//cmdAdd.ExecuteNonQuery();
cmdAdd.Fill(ds);
}
sql = "SELECT memberreportid, typeofcrime, crdatetime,
address, incidentdate, incidenttime, property, victim,
suspect, detail, propertydetail, suspectdetail from
memberreport where " + ddlCategory.SelectedItem.Text + " like
'%" + txtData.Text + "%' and caseprogress='inprogress'";
using (var cmdAdd = new SqlDataAdapter(sql, connAdd))
{
//cmdAdd.ExecuteNonQuery();
cmdAdd.Fill(ds);
}
connAdd.Close();
return ds.Tables[0];
The stacktrace say it's within this area of the code. However, i have
tested the SQL code alone itself and it works. But when i put 2 together,
they say there's an error in my where condition.
PS : I know this SQL codes are easily prone to SQL injection which i will
implement later.
No comments:
Post a Comment