i have one gridview to display search records,one text box for search text and one search button
how can i search data from multiple data tables..
can any one help me please...
Thanks in advance
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Mukesh Kumar TiwariPosted Nov 9, 2013, 1:47 AM
Kavitha ChamarthiPosted Nov 9, 2013, 1:38 AM
Mukesh Kumar TiwariPosted Nov 9, 2013, 1:10 AM
you can also fill the grid without sp like this..
Text_change event of the text box call a function fill_Grid
public void fill_grid()
{
string StrWhere = null;
try
{
Conn = new SqlConnection(ConnString);
if (Conn.State == ConnectionState.Closed)
{
Conn.Open();
}
string query = "select SM.name,SM.add,SM.phn_no,SD.marks1,SD.marks2,SD.marks3 from student_master as SM"+
"+inner join student_detail as AD on SM.stud_id=SD.stud_id where stud_name like'%"txt_search_student.text+"%'";
Cmd = new SqlCommand(query, Conn);
Adp = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
Adp.Fill(ds);
grid_stud_info.DataSource = ds.Tables[0];
Conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,);
}
}
its simple use join query and pass it......thats all..
all the best.......
Mukesh Kumar TiwariPosted Nov 9, 2013, 12:55 AM
{
try
{
Conn = new SqlConnection(ConnString);
if (Conn.State == ConnectionState.Closed)
{
Conn.Open();
}
Cmd = new SqlCommand("call_master_gridfill", Conn);
Cmd.Parameters.AddWithValue("@srno", txt_searching.Text);
Cmd.Parameters.AddWithValue("@ssno", textBox1.Text);
Cmd.CommandType = CommandType.StoredProcedure;
Adp = new SqlDataAdapter(Cmd);
DataSet ds = new DataSet();
Adp.Fill(ds);
grid_view_main.DataSource = ds.Tables[0];
Conn.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message,);
}
}
}
And write a store procedure like this:
ALTER proc [dbo].[call_master_gridfill]
(
@srno varchar(50),
@ssno nvarchar(50)
)
as
begin
select comp.name as'Company Name',comp.address as 'Address',comp.phon_no as'Phone No.',mm.model_name as 'Model Name',
cm.make as 'Make',cm.srno as 'Serail No.',cm.warr_amc as 'W./O.W./AMC',cm.callername as 'Caller Name',
cm.calltype as 'Call Type',cm.fault_desc as 'fault Descripation',cm.nature_complain as 'Nature of Complain',
cm.asignto as 'Assign TO',
cm.service_date as 'Service Date',cm.notes as 'Notes',cm.status as 'Status',cm.accessories as 'Accessories',
cm.charge as 'Charge',cm.serial_support_srno as 'Billing Instruction',cm.total as 'Total'from call_master as cm
inner join company_master as comp on comp.company_id=cm.company_id
inner join model_master as mm on mm.model_id=cm.model_id
where cm.srno like '%'+@srno+ '%' AND cm.serial_support_srno like '%'+@ssno+'%'
end