Click here to Skip to main content
13,001,159 members (63,048 online)
Rate this:
Please Sign up or sign in to vote.
See more:
i have used binding navigator and binding source to insert data and delete data from database but, its not inserting and deleting.... if i delete the data its deleting but there is no change in database and if add its adding but no update in database ...

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.SqlClient;
namespace datanavi
    public partial class Form1 : Form
        SqlConnection con;
        SqlCommand cmd;
        // my table name is dn
        // It has two fields name,age
        // two textbox i m having in form 
        public Form1()
        private void Form1_Load(object sender, EventArgs e)
            // TODO: This line of code loads data into the 'textileDataSet.dn' table. You can move, or remove it, as needed.
        private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
            //this code is not working while inserting
            cmd = new SqlCommand("insert into table dn values '" + textBox1.Text + "','" + textBox2.Text + "'", con);
//i used bindingsource and bindingnavigator control to interact with Database table
Posted 15-Dec-12 21:45pm
Updated 25-Dec-12 18:18pm
Krunal Rohit 16-Dec-12 3:48am
Elaborate your question... Provide some more info..
-Krunal R.
selva_1990 16-Dec-12 3:56am
there is a button available in binding navigator ("add new" with plus symbol)
i double clicked that and wrote command to insert data into database but it showing exception like i mentioned...
Krunal Rohit 16-Dec-12 8:15am
provide your code..
selva_1990 16-Dec-12 8:25am
i updated
Krunal Rohit 16-Dec-12 8:28am
please read it :
selva_1990 16-Dec-12 8:34am
i have seen but could you give one example to insert..,
Krunal Rohit 16-Dec-12 8:36am
void customersBindingSource_AddingNew(object sender, AddingNewEventArgs e)
e.NewObject = DemoCustomer.CreateNewCustomer();
Krunal Rohit 16-Dec-12 8:40am
got something ??
selva_1990 16-Dec-12 8:43am
still i am not clear sir
Krunal Rohit 16-Dec-12 8:47am
First, Don't call me Sir, I'm just 20 years old student... :)
Second, here CreateNewCustome is a method of Customer class.. So define one method and call it as mentioned..
selva_1990 16-Dec-12 8:56am
k k bro cool :)
Krunal Rohit 16-Dec-12 8:58am
Yes, I am..
selva_1990 16-Dec-12 9:04am
but few month back i inserted directly without any coding..., just gave data source and data member for binding source and data binding source to inserted but now not insertin
Krunal Rohit 16-Dec-12 9:08am
For that I need to understand your scenario...
selva_1990 16-Dec-12 9:18am
i ll provide my entire program
Krunal Rohit 16-Dec-12 9:20am
selva_1990 16-Dec-12 10:15am
i gave full scenario..sry for late network prob...
selva_1990 16-Dec-12 10:27am
waiting for ur reply bro dont forgot...
selva_1990 25-Dec-12 8:01am
are u there
Krunal Rohit 25-Dec-12 8:07am
selva_1990 25-Dec-12 8:52am
i have explained all waiting for ur reply
selva_1990 25-Dec-12 8:54am
by default bindingnavigator control contain toolstrip menu like movelast,movefirst,next,previous,add,delete...
in every tutorial no one explaining add & delete so i need how to add data and delete
Krunal Rohit 25-Dec-12 21:17pm
Add new button..
see :
selva_1990 25-Dec-12 21:34pm
I don't want to add button i need to add data into database using binding navigator its urgent you have to help me
Krunal Rohit 25-Dec-12 21:36pm
Have you explore that link ?
selva_1990 25-Dec-12 21:42pm
i have seen but its about adding ... i just neeed to insert data into DB using bindingnavigator
Krunal Rohit 25-Dec-12 21:46pm
Ya its adding, please see at MSDN :

I've given you answer.. you can write code behind this button :)
selva_1990 25-Dec-12 22:04pm

tis not working .. i just add this code into my click event
Krunal Rohit 25-Dec-12 22:34pm
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
// write query for inserting data in DB

selva_1990 25-Dec-12 22:42pm
i have wrote this code there "this.bindingSource1.AddNew();" its right ly know but its not inserting
Krunal Rohit 25-Dec-12 22:44pm
You're not getting me..
I'm telling about : "INSERT INTO TABLE_NAME VALUES VAL1, VAL2, ..."

like this query.. Hope now you understand what I mean.. :)
selva_1990 25-Dec-12 23:06pm
cmd = new SqlCommand("insert into table dn values '" + textBox1.Text + "','" + textBox2.Text + "'", con);

u mean this query
Krunal Rohit 25-Dec-12 23:19pm
selva_1990 26-Dec-12 0:04am
dude its not working...
Krunal Rohit 26-Dec-12 0:12am
selva_1990 26-Dec-12 0:18am
its not showing any error but its not adding in DB if u dont mind can u do one favor for me
Krunal Rohit 26-Dec-12 0:19am
what ?
selva_1990 26-Dec-12 0:32am
can u leave video tutorial or attach full project with one simple example... its my project work
Krunal Rohit 26-Dec-12 0:35am
I can give you after 2 days.. Because my exams are going on.. only 2 papers are left... but for sure, I'll mail you code for that after 2 days.. If you're good with this, provide your mail..
selva_1990 26-Dec-12 0:42am
ya fine... i need insert,delete,update using binding navigator..
i m waiting for ur mail, it'll be more helpful for me.., dont forgot.. ALL BEST FOR Exam :) :)
Krunal Rohit 26-Dec-12 0:51am
Thanks :)

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Since you are pulling data directly from the controls I assume you are not familiar with the BindingNavigator.BindingSource[^] property.

Have a look at Depends4Net - Part 2[^] for an example on how to bind to "custom" elements - which is what you usually have to operate on when you are using SqlCommand and SqlDataReader to access the database.

You can also switch to the Entity Framework, and if you do then you can have a look at:Entity Framework in WinForms[^]

Best regards
Espen Harlinn

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170624.1 | Last Updated 1 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100