I am new in asp.net, i m makeing a one form through which i enter the data into the db, now i want to retrive that data from database to that form ,in form i uses textbox and gridview.. In my db i make a three tables i.e. Pinfo,Acd_dtl and emp_dtl, in these tables i take a one column of id which is unique an all tables. now i want to retrieve data from that tables to my form with the help of search button... to search i take a text box to enter a email id of employee. Now i want that when i fill the email id of employee then all the relevant data of that email id can show me on my form...I take the email id in the table Pinfo.....
so plzzzz help me guyz..............
Madhu KPosted Nov 17, 2010, 3:29 AM
Rahul GoyalPosted Nov 17, 2010, 12:40 AM
Madhu KPosted Nov 16, 2010, 9:03 AM
Rahul GoyalPosted Nov 16, 2010, 7:56 AM
Madhu KPosted Nov 16, 2010, 7:43 AM
inner join Academic_dtl as a on p.id=a.id
inner join Emp_dtl as e on p.id=e.id where p.e_mail="+TextBox21.Text+"
Instead of a.Examination... and e.Name of employee..... write the column names that are to bind the Gridview.
Can you post the 3 table column names you are using so that i can check.
Rahul GoyalPosted Nov 16, 2010, 7:00 AM
Madhu KPosted Nov 16, 2010, 6:49 AM
select p.[name],a.*,e.* from Pinfo as p
inner join Academic_dtl as a on p.id=a.id
inner join Emp_dtl as e on p.id=e.id where p.e_mail="+TextBox21.Text+"
Rahul GoyalPosted Nov 16, 2010, 6:22 AM
Madhu KPosted Nov 16, 2010, 6:02 AM
protected void btnSearch_Click(object sender, EventArgs e)
{
try
{
SqlConnection con3 = new SqlConnection();
con3.ConnectionString = ConfigurationManager.AppSettings["cn"];
{
con3.Open();
}
SqlCommand cmd3 = new SqlCommand("select Job_applied,Name,Date_brith,Sex,Present_add,Permanent_add,Contact_no,Mobile_no,E_mail,Marital_st,Agreement,Min_salary from Pinfo where E_mail=@search", con3);
cmd3.Parameters.Add("@search", SqlDbType.VarChar, 50).Value = TextBox21.Text.ToString();
SqlDataReader dr = cmd3.ExecuteReader();
if (dr.HasRows == false)
{
throw new Exception();
}
if (dr.Read())
{
TextBox1.Text = dr[0].ToString();
TextBox2.Text = dr[1].ToString();
TextBox3.Text = dr[2].ToString();
RadioButtonList1.Text = dr[3].ToString();
TextBox4.Text = dr[4].ToString();
TextBox5.Text = dr[5].ToString();
TextBox6.Text = dr[6].ToString();
TextBox7.Text = dr[7].ToString();
TextBox8.Text = dr[8].ToString();
RadioButtonList2.Text = dr[9].ToString();
RadioButtonList3.Text = dr[10].ToString();
TextBox20.Text = dr[11].ToString();
}
dr.Close();
cmd3.Dispose();
SqlCommand cmd4 = new SqlCommand("select Pinfo.E_mail,Academic_dtl.*,Emp_dtl.* from Pinfo inner join Academic_dtl on Pinfo.id=Academic_dtl.id inner join Emp_dtl on Pinfo.id=emp_dtl.id where Pinfo.E_mail="+TextBox21.Text+"", con3);
SqlDataAdapter da = new SqlDataAdapter(cmd4);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
GridView2.DataSource = dt;
GridView2.DataBind();
cmd4.Dispose();
con3.Close();
}
catch(Exception ex)
{
Response.Write(ex.Message.ToString());
}
}
Rahul GoyalPosted Nov 16, 2010, 5:14 AM
Rahul GoyalPosted Nov 16, 2010, 5:10 AM
Madhu KPosted Nov 16, 2010, 4:46 AM
write foloowing. You need to bind the gridview.
cmd3.Dispose();
SqlCommand cmd4 = new SqlCommand("select Pinfo.E_mail,Academic_dtl.Examination,Emp_dtl.Name of employee from Pinfo inner join Academic_dtl on Pinfo.id=Academic_dtl.id inner join Emp_dtl on Pinfo.id=emp_dtl.id where Pinfo.E_mail=TextBox21.Text.ToString()", con3);
SqlDataAdapter da = new SqlDataAdapter(cmd4);
DataTable dt = new DataTable();
da.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
cmd4.Dispose();
con3.Close();
Tell me if you dint understand.
Rahul GoyalPosted Nov 16, 2010, 4:03 AM
Madhu KPosted Nov 16, 2010, 3:20 AM
select Pinfo.E_mail,Acd_dtl.column2,emp_dtl.column3 from Pinfo
inner join Acd_dtl on
Pinfo.id=Acd_dtl.id
inner join emp_dtl on
Pinfo=emp_dtl.id where Pinfo.E_mail=txtEmail.Text
Rahul GoyalPosted Nov 16, 2010, 2:25 AM
Madhu KPosted Nov 16, 2010, 12:55 AM
select Pinfo.column1,Acd_dtl.column2,emp_dtl.column3 from Pinfo
inner join Acd_dtl on
Pinfo.id=Acd_dtl.id
inner join emp_dtl on
Pinfo=emp_dtl.id
check the link for sqljoins
http://www.w3schools.com/sql/sql_join_inner.asp
Jiteendra SampathiraoPosted Nov 16, 2010, 12:40 AM
In Grid view Between the Columns tag use template fields and there you define the columns what you need.....
In code behind page open the connection string and write the select queries to ur requirement put it in the dataset........
below Links will help you:
http://www.c-sharpcorner.com/UploadFile/jitendra1987/1893/Default.aspx?ArticleID=418874ab-9d12-49af-98b7-6729ab35e59e
http://www.c-sharpcorner.com/UploadFile/jitendra1987/3804/Default.aspx?ArticleID=62298b7b-ea7b-4528-8a7e-5dfe872dfe16
http://www.c-sharpcorner.com/UploadFile/jitendra1987/3848/Default.aspx?ArticleID=274124a2-1c6a-45fb-8ba4-c459c2fbf223
If this post helped you, then tick the "Do you like this Answer" checkbox which is placed at above this post.