hi

can any body help me i want to insert to data base the record save into data access data
but when return to data base the record not exit

this 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 WindowsFormsApplication1
{
    public partial class Form3 : Form
    {
        static string ConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|/data.mdb";
        OleDbConnection Conn = new OleDbConnection(ConStr);
        public Form3()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            //string sql = "INSERT INTO schools (`schoolno`,`schoolname`,`schooltype`,`buldingtype`,`supervisecenter`,`region`,`schoolphone`,`schoolfax`,`schoolemail`,`managername`,`managermobile`,`address`,`dist`,`supervisorname`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
            try
            {
                if (Conn.State.Equals(ConnectionState.Closed))

                    Conn.Open();
                OleDbCommand cmd = new OleDbCommand("INSERT INTO schools(schoolno,schoolname,schooltype,buldingtype,supervisecenter,region,schoolphone,schoolfax,schoolemail,managername,managermobile,address,dist,supervisorname) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?)", Conn);
                cmd.Parameters.Add("@schoolno", OleDbType.VarChar).Value = textBox22.Text;
                cmd.Parameters.Add("@schoolname", OleDbType.VarChar).Value = textBox22.Text; ;
                cmd.Parameters.Add("@schooltype", OleDbType.VarChar).Value = comboBox6.Text;
                cmd.Parameters.Add("@buldingtype", OleDbType.VarChar).Value = comboBox5.Text;
                cmd.Parameters.Add("@supervisecenter", OleDbType.VarChar).Value = comboBox4.Text;
                cmd.Parameters.Add("@region", OleDbType.VarChar).Value = textBox15.Text;
                cmd.Parameters.Add("@schoolphone", OleDbType.VarChar).Value = textBox14.Text;
                cmd.Parameters.Add("@schoolfax", OleDbType.VarChar).Value = textBox12.Text;
                cmd.Parameters.Add("@schoolemail", OleDbType.VarChar).Value = textBox20.Text;
                cmd.Parameters.Add("@managername", OleDbType.VarChar).Value = textBox19.Text;
                cmd.Parameters.Add("@managermobile", OleDbType.VarChar).Value = textBox18.Text;
                cmd.Parameters.Add("@address", OleDbType.VarChar).Value = textBox17.Text;
                cmd.Parameters.Add("@dist", OleDbType.VarChar).Value = textBox16.Text;
                cmd.Parameters.Add("@supervisorname", OleDbType.VarChar).Value = textBox13.Text;
                cmd.ExecuteNonQuery();
                MessageBox.Show("تم إدخال السجل بنجاح");
                this.Hide();
                Form2 f2 = new Form2();
                f2.Show();

            }
            catch (OleDbException ex)
            {
                MessageBox.Show(ex.Message);

            }
            finally
            {
                Conn.Close();
            }
        }
    }
}

help me please

Run it outside of Visual Studio and check if it inserts the record.

the same prpblem exist

In line 45 the ExecuteNonQuery returns a value (an Int32). Put code in there to get it and display the value.

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.