Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hello, Guys, I am facing another issue that is
my form getting freeze and close  on onload please check my code and suggest me the solution 
Thanks in advance

What I have tried:

<pre>con_string.ConnectionString = @"Provider = Microsoft.ACE.OLEDB.12.0;Data Source =|DataDirectory|\Restaurant.accdb;Persist Security Info=False";
            con_string.Open();
            DataSet dsa2 = new DataSet();
            DataTable dt2 = new DataTable();
            dsa2.Tables.Add(dt2);
            OleDbDataAdapter da2 = new OleDbDataAdapter();
            da2 = new OleDbDataAdapter(@"SELECT column2," +
"Sum(MediumVal) As [Dine In] " +
                "Sum(LargeVal) As [Deliery], " +
                "Sum(RoyalVal) As [Take Away], " +
"From ( " +
"SELECT " +
"column2 As [column2]" +
",Switch(column3 like 'DineIn%', 1,True,0) As [MediumVal] " +
                ",Switch(column3 like 'Delivery%',1,True,0) As [LargeVal], " +
                ",Switch(column3 like 'TakeAway%', 1,True,0) As [RoyalVal] " +
                                    " FROM Total " + " Where [Date] between #" + System.DateTime.Now.ToString("MM/dd/yyyy") + "# AND #" + System.DateTime.Now.AddDays(1).ToString("MM/dd/yyyy") + "# ", con_string);
            MessageBox.Show(@"SELECT column2," +
"Sum(MediumVal) As [Dine In] " +
                "Sum(LargeVal) As [Deliery], " +
                "Sum(RoyalVal) As [Take Away], " +
"From ( " +
"SELECT " +
"column2 As [column2]" +
",Switch(column3 like 'DineIn%', 1,True,0) As [MediumVal] " +
                ",Switch(column3 like 'Delivery%',1,True,0) As [LargeVal], " +
                ",Switch(column3 like 'TakeAway%', 1,True,0) As [RoyalVal] " +
                                    " FROM Total " + " Where [Date] between #" + System.DateTime.Now.ToString("MM/dd/yyyy") + "# AND #" + System.DateTime.Now.AddDays(1).ToString("MM/dd/yyyy") + "#");
            da2.Fill(dt2);
            dataGridView1.DataSource = dt2;
            con_string.Close();
            dataGridView1.Columns[0].Width = 286;
            dataGridView1.Columns[1].Width = 180;
            dataGridView1.Columns[2].Width = 180;
            dataGridView1.Columns[3].Width = 180;
            dataGridView1.Columns[4].Width = 180;
            dataGridView1.Columns[5].Width = 180;
            int sum = 0;
            for (int i = 0; i < dataGridView1.Rows.Count; ++i)
            {
                sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[1].Value);
            sum += Convert.ToInt32(dataGridView1.Rows[i].Cells[2].Value) + Convert.ToInt32(dataGridView1.Rows[i].Cells[3].Value);
            dataGridView1.Rows[i].Cells[0].Value = sum;
                sum = 0;
            }
            MessageBox.Show(y);
            
for (int i = 1; ei < dataGridView1.Columns.Count; i++)
{
                double sum = 0;
                for (int j = 0; j < dataGridView1.Rows.Count; j++)
                {
                    sum += Convert.ToDouble(dataGridView1.Rows[[j],[i]]);
                }
                dataGridView1.Rows[dataGridView1.Rows.Count].Cells[i].Value = sum.ToString();
            }
            dataGridView1.Columns[4].Width = 180;
Posted
Updated 20-Oct-17 13:39pm
Comments
cvogt61457 20-Oct-17 17:08pm    
You aren't giving us any information to determine what the problem is.

We need more of the code.
Where is it freezing?

Run in the debugger and see which line the execution is freezing at.
Member 9983063 20-Oct-17 17:49pm    
here i get error da2.Fill(dt2);
Peter_in_2780 20-Oct-17 18:07pm    
I'd be willing to bet that you have a typo somewhere in that humungous query string.
CHill60 20-Oct-17 18:13pm    
A virtual 5
(I'm not taking the bet)
CHill60 20-Oct-17 18:13pm    
Use a parameterised query rather than concatenation and you might find your problem goes away

1 solution

Already 92 questions and you still don't the basics of debugging
C#
da2 = new OleDbDataAdapter(@"SELECT column2," +
"Sum(MediumVal) As [Dine In] " +
"Sum(LargeVal) As [Deliery], " +
"Sum(RoyalVal) As [Take Away], " +
"From ( " +
"SELECT " +
"column2 As [column2]" +
",Switch(column3 like 'DineIn%', 1,True,0) As [MediumVal] " +
",Switch(column3 like 'Delivery%',1,True,0) As [LargeVal], " +
",Switch(column3 like 'TakeAway%', 1,True,0) As [RoyalVal] " +
" FROM Total " + " Where [Date] between #" + System.DateTime.Now.ToString("MM/dd/yyyy") + "# AND #" + System.DateTime.Now.AddDays(1).ToString("MM/dd/yyyy") + "# ", con_string);

You build a query from 16 strings, it don't work and you don't even check if resulting string is a correct SQL query.
First thing to do: store the query in a variable and check the syntax, pay special attention to misplaced commas.
 
Share this answer
 
Comments
Member 9983063 21-Oct-17 3:05am    
bro, i am still facing the same issue even with your code also here
da2.Fill(dt2);
Patrice T 21-Oct-17 3:09am    
it is your code!
read last sentence.

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