Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hello,

I am looking for a one solution for datagridview. two datagridview is there one dg1 and second dg2. one combobox and one button is also there. Now I want to query solution like,

When i select january from combobox and click on button after that, as output I can able to show paid and unpaid customer record from the database in dg1 and dg2.

so basically, when i select january month i can able to see dg1 as paid record of customer and dg2 as unpaid record of customer.

Please Help me If any one have solution of my problem then for my current working project.

Thanks & Regards,
Vaishali Parmar.

What I have tried:

i added combobox months by below line,

cyear.DataSource = System.Globalization.DateTimeFormatInfo.InvariantInfo.MonthNames
Posted
Updated 4-Oct-18 5:59am
v2
Comments
Christian Graus 4-Oct-18 1:42am    
You are asking us to do your work. That's not what you're being paid for. You need to get your records from your database, and put them into your grid. You can ask specific questions when you're stuck
Member 11774405 4-Oct-18 7:59am    
Hello Christian Graus.
I think you have something confusion. first, maybe you has not read the question properly. second, I don't asking to anyone to do my own works as free. here I have simple asked (as a any help) that which query I will used for my output . and input as Logic I described it above. so i just want to clear that how work that query part paid and unpaid in both Dg1 and Dg2 records from the databse.
ZurdoDev 4-Oct-18 10:13am    
How to do this? You have to write the code. Have one stored procedure that returns data for the first grid and a second stored procedure that returns data for the second grid. It's pretty simple so we are not sure what you are asking.
M4rLask 4-Oct-18 11:20am    
If you need us to give you the query, maybe you should consider hiring a professional for the job,We do not provide 'the code', only help to a specific problem

1 solution

SQL
Create PROCEDURE SPtblStatus
	@Month	varchar(50)	=null
		
AS
BEGIN
	select * from Codeproject.tblStatus where Status='Paid' and Month=@Month
	select * from Codeproject.tblStatus where Status='UnPaid' and Month=@Month
END
GO


This stored procedure returns two results. get those into application.

C#
DataSet ds = new DataSet();
           using (var con = new SqlConnection("Data Source=DESKTOP-0V1BRD9;Initial Catalog=StackOverflow;Persist Security Info=True;User ID=sa;Password=sa_123+"))
           using (var cmd = new SqlCommand("SPtblStatus", con))
           using (var da = new SqlDataAdapter(cmd))
           {
               cmd.CommandType = CommandType.StoredProcedure;
               SqlParameter param = new SqlParameter("@Month", "Feb");
               cmd.Parameters.Add(param);
               da.Fill(ds);
           }

           if (ds.Tables.Count > 0)
           {
               dataGridView1.DataSource = ds.Tables[0];
               dataGridView2.DataSource = ds.Tables[1];
           }
 
Share this answer
 
Comments
Member 11774405 4-Oct-18 23:40pm    
Thank you.
[no name] 6-Oct-18 1:01am    
Welcome. If your query is resolved please accept this solution.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900