hi,
i have a drop down list populated with column names of tbl_student and a text box for searching specific value coresponding to the value selected in drop down list
i do not have much knowlewdge about qureies might b m lacking there
error is Incorrect syntax near '='
my code is
private void Search(string field)
{
DataTable dt = new DataTable();
SqlConnection connection = new SqlConnection(GetConnectionString());
try
{
connection.Open();
//string sqlStatement = "SELECT * FROM tbl_student WHERE student_id = @student_id";
string strQuery = "SELECT * FROM tbl_student WHERE" + ddl_SearchBy.SelectedValue + "= @" + ddl_SearchBy.SelectedValue + "";
SqlCommand sqlCmd = new SqlCommand(strQuery, connection);
sqlCmd.Parameters.AddWithValue("@" + ddl_SearchBy.SelectedValue+"", field);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
}
// NO RECORDS FOUND
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}