如何在访问数据库中插入整数值?

时间:2016-07-27 17:01:02

标签: c# datagridview ms-access-2007

我试图通过使用datagridview将Integer值插入MS-Access数据库,但是其他字符串值输入成功但整数不是。我也使用调试器但是当调试器到达那一行时它显示我的null值。在我的数据库中,我使用Memo作为可用性的数据类型,这是我的代码和可能的快照

private void dataGridView1_RowLeave(object sender, DataGridViewCellEventArgs e)
        {
            try
            {

            if (dataGridView1.IsCurrentRowDirty)
            {
                string connectionString = null;
                connectionString = ConfigurationManager.ConnectionStrings["AccessConnectionString"].ConnectionString;
                con.ConnectionString = connectionString;

                string cmd1 = "insert into Medicine_Available_Detail(Medicine_Name,Dealer_name,Availability) values(?,?,@Availability)";
                OleDbCommand cmd = new OleDbCommand(cmd1, con);

                cmd.CommandType = CommandType.Text;

                string Medicine_Name = dataGridView1.Rows[e.RowIndex].Cells["Medicine_Name"].Value.ToString();
                cmd.Parameters.AddWithValue("@Medicine_Name", Medicine_Name);

                string Dealer_name = dataGridView1.Rows[e.RowIndex].Cells["Dealer_name"].Value.ToString();
                cmd.Parameters.AddWithValue("@Dealer_name", Dealer_name);

 string Availability = dataGridView1.Rows[e.RowIndex].Cells["Availability"].Value.ToString();
                cmd.Parameters.AddWithValue("@Availability", Availability);


                con.Open();
                int n = cmd.ExecuteNonQuery();
                con.Close();
                if (n > 0)
                {

                    MessageBox.Show("Data Inserted Successfully", "Data Inserted ", MessageBoxButtons.OK, MessageBoxIcon.Information);


                }

            }
            }
            catch (Exception ex)
            {

            Load_data();
            dataGridView1.Refresh();

           }
}

enter image description here enter image description here

0 个答案:

没有答案