Rahul Goyal

Rahul Goyal

  • NA
  • 57
  • 63.9k

Retrive a data from database and show in text boes and gridview

Nov 15 2010 3:58 AM
hiiii
i am new in asp.net. I make a one project in which we use textboxes and gridview to save the data in database.....
now i place a one search text box and a button on that page through which i enter the data into the database...
now i want that when i fill the email id of any person in search text box and click on the search button, then all data regarding that email id show me on that page from where i enter the data in to the data base(means the textboxes data show me in textboxes and the gridview  data show me in gridview. NOte that i have only one form). 
I try to do it but no result come....
so plzzzz help me!!!!!!!!!!!!!

my code shown below:


protected void Button4_Click(object sender, EventArgs e)
    {
        SqlConnection con3 = new SqlConnection();
        con3.ConnectionString = ConfigurationManager.ConnectionStrings["cn"].ConnectionString;
        {
            con3.Open();
        }
        DataTable dt=new DataTable();
        SqlCommand cmd3 = new SqlCommand("select * from Pinfo where id=@E_mail", con3);
        SqlDataAdapter da = new SqlDataAdapter(cmd3);
        cmd3.Parameters.AddWithValue("@E_mail", User);
        da.Fill(dt);
        if(dt.Rows.Count>0)
        {
            TextBox1.Text = dt.Rows[0]["Job_applied"].ToString();
            TextBox2.Text = dt.Rows[0]["Name"].ToString();
            TextBox3.Text = dt.Rows[0]["Date_brith"].ToString();
            RadioButtonList1.Text = dt.Rows[0]["Sex"].ToString();
            TextBox4.Text = dt.Rows[0]["Present_add"].ToString();
            TextBox5.Text = dt.Rows[0]["permanent_add"].ToString();
            TextBox6.Text = dt.Rows[0]["Contact_no"].ToString();
            TextBox7.Text = dt.Rows[0]["Mobile_no"].ToString();
            TextBox8.Text = dt.Rows[0]["E_mail"].ToString();
            RadioButtonList2.Text = dt.Rows[0]["Marital_st"].ToString();
            RadioButtonList3.Text = dt.Rows[0]["Agreement"].ToString();
            TextBox20.Text = dt.Rows[0]["Min_salary"].ToString();
        }        
        con3.Close();
        cmd3.ExecuteNonQuery();
        cmd3.Dispose();
    }

Answers (4)