SqlConnection con=new SqlConnection("database=cvp;server=.;integrated security=true;");
SqlCommand cmd;
SqlDataAdapter da;
DataSet ds;
string query,tablename;
protected void Button3_Click(object sender, EventArgs e)
{
//code for ok button
string slct = "Select * ";
string tblcol = DropDownList1.SelectedItem.ToString();
string frm = " From ";
string whr = " where ";
string sign = DropDownList2.SelectedItem.ToString();
string val = " " +TextBox2.Text;
if (tblcol == "EmployeeId")
{
tablename=
"Employee";
}
else if (tblcol == "ProductId")
{
tablename=
"Product";
}
else if(tblcol=="CustomerId")
{
tablename =
"Customer";
}
query = slct + frm + tablename + whr + tblcol + sign + val;
ListBox1.Items.Add(query);
}
protected
void Button4_Click(object sender, EventArgs e)
{
//code for submit button
cmd =
new SqlCommand();
string ss = ListBox1.SelectedItem.ToString();
if (ss == null)
ss = query;
cmd.CommandText = ss;
cmd.Connection = con;
SqlDataReader dr;
con.Open();
dr=cmd.ExecuteReader();
if (dr.HasRows)
{
//while (dr.Read())
//{
// Response.Write(dr.GetSqlInt32(0)+" ");
// Response.Write(dr.GetString(1)+" ");
// Response.Write(dr.GetSqlInt32(2) + "<br><br>");
//}
DataTable dt = new DataTable(tablename);
DataColumn dc1 = new DataColumn(dr.GetName(0));
DataColumn dc2 = new DataColumn(dr.GetName(1));
DataColumn dc3 = new DataColumn(dr.GetName(2));
dt.Columns.Add(dc1);
dt.Columns.Add(dc2);
dt.Columns.Add(dc3);
while (dr.Read())
{
DataRow dr1 = dt.NewRow();
dr1[0] = dr.GetSqlInt32(0);
dr1[1] = dr.GetString(1);
dr1[2] = dr.GetSqlInt32(2);
dt.Rows.Add(dr1);
}
GridView1.DataSource = dt;
GridView1.DataBind();
}
con.Close();
}