Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
ex.
A 01/01/2011
B 01/01/2011
C 01/01/2011
D 01/01/2011
A 01/02/2011
B 01/02/2011
D 01/02/2011
A 01/03/2011
D 01/03/2011

The query were planning to use ?

SELECT DISTINCT Alphabets, dateReceive FROM
database
ORDER BY Alphabets

using List<string>

Our expected output
[{A,B,C,D},{A,B,D},{A,D}


C#
using (var conn = new SqlConnection("Data Source=SERV-PC\\MSQLSERVER;Initial Catalog=MyDatabase;Integrated Security=True"))
            {
                using (var cmd = new SqlCommand())
                {
                    cmd.Connection = conn;
                    cmd.CommandText = "SELECT DISTINCT [ColumnA], [DateReceive] FROM [MyDatabase].[dbo].[dummy] WHERE [ColumnA]=@loca  AND [DateReceive] BETWEEN '01/01/2013' and '01/07/2013' ";
                    cmd.Parameters.AddWithValue("@loca", DropDownList1.SelectedValue.ToString());
                    conn.Open();

                    using (var reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            var tmp = reader["ColumnA"];
                            if (tmp != DBNull.Value)
                            {
                                ListBox1.Items.Add(reader["ColumnA"].ToString());
                            }
                        }
                    }
                }
            }
Posted
Updated 18-Jan-14 2:00am
v2
Comments
OriginalGriff 18-Jan-14 7:33am    
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Use the "Improve question" widget to edit your question and provide better information.

1 solution

You asked this twice. Please ask once and EDIT your question to add detail if asked for it.
 
Share this answer
 
Comments
Maciej Los 18-Jan-14 17:31pm    
What?
I can see one OP's question only ;)
Similar question was asked by: http://www.codeproject.com/script/Membership/View.aspx?mid=10532857
Christian Graus 18-Jan-14 17:47pm    
The same question was asked twice, I just answered the other one. A lot of people create multiple accounts, but there's no way the other question I saw was not the same as this one.

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