C#数据gridview到ms访问/我的代码错误请帮助当前.. [英] C# Data gridview to ms access /my code error please help for currect..

查看:52
本文介绍了C#数据gridview到ms访问/我的代码错误请帮助当前..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication1
{
    public partial class Form11 : Form
    {
        
        declr objcon = new declr();
        private string cmd;
        OleDbCommand com;

        DataTable objDT;
        DataRow objDR;

        string CD;
        string ITM;
        int QT;
        decimal RTE;
        decimal TOT;
       

        public Form11()
        {
            InitializeComponent();
        }

        private void textBox5_KeyPress(object sender, KeyPressEventArgs e)
        {
         
        }

        private void button1_Click(object sender, EventArgs e)
        {

            foreach (DataRow dr in objDT.Rows)
            {
                CD = Convert.ToString(dr["code"]);
                ITM = Convert.ToString(dr["item"]);
                QT = Convert.ToInt32(dr["qty"]);
                RTE = Convert.ToInt64(dr["rate"]);
                
                cmd = "insert into sale2(code,item,qty,rate)values('" + CD.ToString() + "','" + ITM.ToString() + "'," + QT.ToString() + "," + RTE.ToString() + ")";
                com = new OleDbCommand(cmd, objcon.con);
                com.ExecuteNonQuery();
            }
            MessageBox.Show("           SAVED          ");
        }

        private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (Char)Keys.Enter)
            {
                if (textBox1.Text == "")
                {
                    MessageBox.Show("Enter Item");
                }
                else
                {

                    textBox2.Focus();
                }
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (Char)Keys.Enter)
            {
                if (textBox2.Text == "")
                {
                    MessageBox.Show("Enter Item");
                }
                else
                {

                    textBox3.Focus();
                }
            }
        }

        private void textBox3_KeyPress(object sender, KeyPressEventArgs e)
        {
            if (e.KeyChar == (Char)Keys.Enter)
            {
                if (textBox3.Text == "")
                {
                    MessageBox.Show("Enter Item");
                }
                else
                {

                    textBox4.Focus();
                }
            }
        }

        private void textBox4_KeyPress(object sender, KeyPressEventArgs e)
        {
            base.OnKeyPress(e);
            if (char.IsLetter(e.KeyChar))
            //if (textBox9.Visible == false)
            //{
            {
                e.Handled = true;
                //MessageBox.Show("Enter Digit Only");

                // char is letter
            }

            {
                if (e.KeyChar == (Char)Keys.Enter)
                {
                    int RowIndex = 0;
                    dataGridView1.Rows.Add();

                    RowIndex = dataGridView1.Rows.Count - 2;

                    // insert values from textboxe to DataGridView
                    dataGridView1[0, RowIndex].Value = textBox1.Text;
                    dataGridView1[1, RowIndex].Value = textBox2.Text;
                    dataGridView1[2, RowIndex].Value = textBox3.Text;
                    dataGridView1[3, RowIndex].Value = textBox4.Text;
                    dataGridView1[4, RowIndex].Value = textBox5.Text;


                    dataGridView1.Refresh();


                    // Clear textboxes and focus for new entry
                    //textBox1.Text = "";
                    //textBox2.Text = "";

                    textBox1.Focus();
                }
            }
        }

        private void Form11_Load(object sender, EventArgs e)
        {
            //if (objcon.con.State != ConnectionState.Open)
            //{
            //    objcon.con.Open();
            //}
        }
    }
}





SHOUTING已删除 - OriginalGriff [/ edit]



[edit]SHOUTING removed - OriginalGriff[/edit]

推荐答案

确定无法确定您的错误在哪里..但您需要在转换前检查空值。你能告诉我们实际的错误或问题是什么吗?
OK not sure where your error is..but you need to check for nulls before converting. Could you tell us what the actual error or issue is?


这篇关于C#数据gridview到ms访问/我的代码错误请帮助当前..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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