3 Replies - 38079 Views - Last Post: 23 December 2009 - 07:20 AM Rate Topic: -----

#1 omart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-December 09

insert data from datagridview into database

Posted 19 December 2009 - 04:13 AM

Hi all,
how to insert data into a database by entering data in a datagridview.
thank you for your help
Is This A Good Question/Topic? 0
  • +

Replies To: insert data from datagridview into database

#2 karimi  Icon User is offline

  • Banned
  • member icon

Reputation: -9
  • View blog
  • Posts: 104
  • Joined: 29-May 09

Re: insert data from datagridview into database

Posted 19 December 2009 - 05:47 AM

View Postomart, on 19 Dec, 2009 - 03:13 AM, said:

Hi all,
how to insert data into a database by entering data in a datagridview.
thank you for your help


On Edit event handler of datagrid view
string somevalue=Datagrid1.SelectedRow.column[0].EditedFormatedValue();
// query here

This post has been edited by karimi: 19 December 2009 - 05:52 AM

Was This Post Helpful? 0
  • +
  • -

#3 FlashM  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 382
  • View blog
  • Posts: 1,195
  • Joined: 03-December 09

Re: insert data from datagridview into database

Posted 19 December 2009 - 12:23 PM

I posted an answer and some sample code just yesterday to a very similar question you are asking. Look at this thread:
http://www.dreaminco...topic145872.htm
Was This Post Helpful? 1
  • +
  • -

#4 omart  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 12-December 09

Re: insert data from datagridview into database

Posted 23 December 2009 - 07:20 AM

Hi,
I want that clicking on the button, the changes (insert, update, delete) made on the datagridview will be transmitted in the database.
The problem is that when inserting or removing data it appears nothing, neither error nor the Messagebox and changes are not made in the database.
Here is my code


 private void button2_Click(object sender, EventArgs e)
		{
			string connectionString = "Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Documents and Settings\\Administrateur\\Mes documents\\stockage.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True";
			c.ConnectionString = connectionString;
	   //   SqlDataAdapter d = new SqlDataAdapter("select Manip.date, Manip.qte_entre, Manip.qte_vente, Manip.qte_perte, Manip.qte_retour, Manip.prix_ht, Produit.stock_min from Manip, Produit where Produit.nom_pdt='" + nom_selct + "'and Manip.nom_p='" + nom_selct + "'", c);

			SqlDataAdapter d = new SqlDataAdapter("select Manip.date, Manip.qte_entre, Manip.qte_vente, Manip.qte_perte, Manip.qte_retour, Manip.prix_ht from Manip where  Manip.nom_p='" + nom_selct + "'", c);
				
			SqlCommandBuilder cb = new SqlCommandBuilder(d);
					   
			DataTable dt = new DataTable();

			d.Fill(dt);
		   
			dt.TableNewRow+=new DataTableNewRowEventHandler(dt_TableNewRow);
			dt.RowDeleted+= new DataRowChangeEventHandler(dt_RowDeleted);
			//dt.RowChanged+=new DataRowChangeEventHandler(dt_RowChanged);
			
		}
	   
		void dt_TableNewRow(object sender, DataTableNewRowEventArgs e)
		{

			try
			{
				d.Update(dt);
				MessageBox.Show("L'insertion successful!!!!!");
			}

			catch
			{
				MessageBox.Show("Insertion failed !!!!!!");
			}

		}

		void dt_RowDeleted(object sender, DataRowChangeEventArgs e)
		{
			try
			{
				d.Update(dt);
				MessageBox.Show("Deleted successfully!!!!!");
			}

			catch
			{
				MessageBox.Show("error suppression !!!!!!");
			}
		}








Thank you for your help
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1