从 dataGridView1.Rows.Clear() 直到我的代码结束 [英] from dataGridView1.Rows.Clear() until end to my code

查看:60
本文介绍了从 dataGridView1.Rows.Clear() 直到我的代码结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请让我解释一下,我的 Visual Studio Pro 代码中有一些奇怪的地方.没有断开回路的错误信息.似乎我放弃检查销售点项目的所有文件是否有问题.所以直到下面的代码工作正常.

Please Let me explain of there is something weird going on to my codes with my visual studio pro. There are no error messages of disconnected loops. It seems like I give up to check something wrong all files of my point of sales project. So until code below works fine.

 private void button1_Click(object sender, EventArgs e)
        {
            try
            {

                for (int i = 0; i < dataGridView1.Rows.Count; i++)
                {

                    MySqlCommand cmd = new MySqlCommand();
                    cmd.Connection = con;

                    cmd.CommandText = "Insert into salesproducts(saleid,productname,qty,grosstotal)values(@saleid,@productname,@qty,@grosstotal)";
                    cmd.Parameters.AddWithValue("@saleid", lbinvoice.Text);
                    cmd.Parameters.AddWithValue("@productname", dataGridView1.Rows[i].Cells[2].Value);
                    cmd.Parameters.AddWithValue("@qty", dataGridView1.Rows[i].Cells[3].Value);
                    cmd.Parameters.AddWithValue("@grosstotal", dataGridView1.Rows[i].Cells[4].Value);


                    MySqlCommand cmd1 = new MySqlCommand();
                    cmd1.Connection = con;
                    cmd1.CommandText = "insert into salesmain(id,date,time,cashername,qty,grosstotal)values(@id,@date,@time,@cashername,@qty,@grosstotal)";
                    cmd1.Parameters.AddWithValue("@id", lbinvoice.Text);
                    cmd1.Parameters.AddWithValue("@date", lbldate.Text);
                    cmd1.Parameters.AddWithValue("@time", lbltime.Text);
                    cmd1.Parameters.AddWithValue("@cashername", label6.Text);
                    cmd1.Parameters.AddWithValue("@qty", lbitems.Text);

                    cmd1.Parameters.AddWithValue("@grosstotal", lbtotal.Text);

                    con.Open();
                   int x = cmd.ExecuteNonQuery();
                   int y = cmd1.ExecuteNonQuery();

                    MessageBox.Show("Record added ..........");


                    updatedb();


                   }

               }

           catch (Exception ex)
          {
              //MessageBox.Show(ex.Message);
        }

       finally
      {
          con.Close();
      }
    }


// everything worked fine of project till now......

但是在添加这些代码之后像现在这样然后没有任何效果.

but after add these codes from like this now then nothing worked.

                    updatedb();

        //Nothing worked from here...

                    dataGridView1.Rows.Clear();
                    lbtotal.Text = "0";
                    lbitems.Text = "0";
                    txtno.Focus();
                    totalPrice = 0;

                con.Close();
                invoice();
     }
           }
        catch (Exception ex)
        {
            //MessageBox.Show(ex.Message);
        }

        finally
        {
            con.Close();
        }
       }

抱歉,我无法显示图片的完整截图,或者这里没有任何权限.请点击以下链接.

Sorry, I couldn't display the picture wholly screenshot or there is no permission here whatever. Please click down the below links.

请在此处观看销售窗口

那么请观看此视频以了解什么不起作用

我希望在不添加额外文件代码的情况下找到解决方案.谢谢

I hope to find a solution without adding extra codes of files. Thanks

推荐答案

我刚刚删除了 catch 块,并在下面的行中看到了这个错误.

I've just deleted catch block and seen this error on the line below.

// the error was pops to -->`string itmno = `dataGridView1.Rows[row].Cells[1].Value.ToString();` 

错误是:

System.NullReferenceException
      HResult=0x80004003
      Message=Object reference not set to an instance of an object.
      Source=superpos3
      StackTrace:
       at superpos3.salesn.updatedb() in D:\superpos3\superpos3\superpos3\salesn.cs:line 174
       at superpos3.salesn.button1_Click(Object sender, EventArgs e) in D:\superpos3\superpos3\superpos3\salesn.cs:line 258
       at System.Windows.Forms.Control.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnClick(EventArgs e)
       at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
       at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
       at System.Windows.Forms.Control.WndProc(Message& m)
       at System.Windows.Forms.ButtonBase.WndProc(Message& m)
       at System.Windows.Forms.Button.WndProc(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
       at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
       at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
       at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at superpos3.Program.Main() in D:\superpos3\superpos3\superpos3\Program.cs:line 19

这篇关于从 dataGridView1.Rows.Clear() 直到我的代码结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆