hello everyone. I am doing a program with c# DatabaseMicrosoftAcces

And I got error Overflow. It points out in ExecuteQuery();
pls help me.

Here's my code

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 sad
{
    public partial class SignIn : Form
    {
        private OleDbConnection personalConn;
        private OleDbCommand oleDbCmd = new OleDbCommand();
        private String connParam = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\EtaYuy\Documents\Databases.mdb;Persist Security Info=False";

        public SignIn()
        {
            personalConn = new OleDbConnection(connParam);
            InitializeComponent();

        }



       private void button1_Click(object sender, EventArgs e)
       {
           Close();

           T frm = new T();
           frm.Show();


       }

       private void button2_Click(object sender, EventArgs e)
       {

               personalConn.Open();
               oleDbCmd.Connection = personalConn;



           oleDbCmd.CommandText = "insert into Personaldata(Bloclno,Lotno,Numberofoccupants,Firstname,Familyname,Dateofbirth,Age,Bloodtype,Placeofbirth,Religion) values ('" + this.textBox1.Text + "','" + this.textBox2.Text + "','" + this.textBox3.Text + "','" + this.textBox4.Text + "','" + this.textBox5.Text + "','" + this.textBox6.Text + "','" + this.textBox7.Text + "','" + this.textBox8.Text + "','" + this.textBox9.Text + "','" + this.textBox10.Text + "');";

           oleDbCmd.CommandText = "insert into Spouse(Firstname,Familyname,Dateofbirth,Age,Bloodtype,Placeofbirth,Religion,Startofoccupancy,Contactnumber,NumberofChildren,Numberofdogs,Vaccinatedwithantirabies) values ('" + this.textBox11.Text + "','" + this.textBox12.Text + "','" + this.textBox21.Text + "','" + this.textBox13.Text + "','" + this.textBox14.Text + "','" + this.textBox15.Text + "','" + this.textBox16.Text + "','" + this.textBox17.Text + "','" + this.textBox18.Text + "','" + this.textBox22.Text + "','" + this.textBox25.Text + "','" + this.textBox19.Text + "');"; 
           int temp = oleDbCmd.ExecuteNonQuery();// error here
               if (temp > 0)
               {
                   textBox1.Text = null;
                   textBox2.Text = null;
                   textBox3.Text = null;
                   textBox4.Text = null;
                   textBox5.Text = null;
                   textBox6.Text = null;
                   textBox7.Text = null;
                   textBox8.Text = null;
                   textBox9.Text = null;
                   textBox10.Text = null;
                   textBox11.Text = null;
                   textBox12.Text = null;
                   textBox21.Text = null;
                   textBox13.Text = null;
                   textBox14.Text = null;
                   textBox15.Text = null;
                   textBox16.Text = null;
                   textBox17.Text = null;
                   textBox18.Text = null;
                   textBox22.Text = null;

                   textBox25.Text = null;
                   textBox19.Text = null;

                   MessageBox.Show("Record Successfuly Added");

               }
               else
               {
                   MessageBox.Show("Record Fail to Added");
               }
               personalConn.Close();
           }



       private void SignIn_Load(object sender, EventArgs e)
       {

       }


}




    }

Thank you

Since we don't know your table definition, I can't point to the exact problem, but you are trying to store something in a field that isn't large enough to hold the value you are attempting to place there. This most likely is a numeric field.

You are also attempting to place two commands into one command variable. You can do this, but you need to execute the command before you change it. How you have it now is you are only executing the second command.

And on another topic, learn to use parameters. Your setting yourself up for a SQL Injection attack.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.