我的表格冻结并关闭onload

我的表格冻结并关闭onload

本文介绍了我的表格冻结并关闭onload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,伙计们,我正面临另一个问题

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;

推荐答案

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);



您从中构建查询16个字符串,它不起作用,你甚至不检查结果字符串是否是正确的SQL查询。

首先要做的事情:将查询存储在变量中并检查语法,特别注意错位的逗号


这篇关于我的表格冻结并关闭onload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 22:28