when i put one query in textbox and click button then how to show their query output in grid view or repeater or data list in same page asp.net c#
my code
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getquery();
}
}
protected void btn_query_Click(object sender, EventArgs e)
{
con = new SqlConnection(strcon);
con.Open();
SqlCommand cmd = new SqlCommand("sp_query", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@query_name",txt_query_name.Text);
cmd.Parameters.AddWithValue("@queries",txt_query.Text);
cmd.ExecuteNonQuery();
con.Close();
getdata();
getquery();
}
void getquery()
{
con = new SqlConnection(strcon);
con.Open();
string query = txt_query.Text;
SqlCommand cmd = new SqlCommand("sp_query_select", con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@condition", txt_query.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataTable dt = new DataTable();
da = new SqlDataAdapter(cmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
query_repeat.DataSource = dt;
query_repeat.DataBind();
}
else
{
query_repeat.DataSource = null;
query_repeat.DataBind();
}
}
protected void query_repeat_ItemCommand(object source, RepeaterCommandEventArgs e)
{
getquery();
}