connection error

xnanx

New member
Joined
Nov 4, 2013
Messages
1
Programming Experience
Beginner
I'm starting a new C #

But the insert does not work
What could be the problem
The error does not
But it does not insert
C#:
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 Ole_DB_p1
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        OleDbConnection baglanti = new OleDbConnection();
        OleDbCommand ekle = new OleDbCommand();

        private void button1_Click(object sender, EventArgs e)
        {
            baglanti.ConnectionString = "provider = Microsoft.jet.Oledb.4.0;Data Source =data.mdb";
            baglanti.Open();

            ekle = baglanti.CreateCommand();
            ekle.CommandText = "Insert Into Tablo(adi,soyadi,bolum) VALUES (@adi,@soyadi,@bolum)";
            ekle.Parameters.Add("@adi", textadi);
            ekle.Parameters.Add("@soyadi", textsoyadi);
            ekle.Parameters.Add("@bolum", textBolum);
            {
                baglanti.Close();
            }
        }

        private void textadi_TextChanged(object sender, EventArgs e)
        {
        }
    }
}
 
Last edited by a moderator:
Firstly, I've removed all the useless blank lines from your post. If you're going to make it harder for us to read your posts then we'll either just not read it and you miss out or we'll read it and get annoyed. You don't want either of those, do you?

Anyway, the issue is that you never actually execute the command. You open the connection, create and configure the command, then close the connection. If you don't execute the command then nothing useful will happen. Check this out:

Retrieving and Saving Data in Databases
 
Back
Top Bottom