Guest User

Untitled

a guest
Sep 1st, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.44 KB | None | 0 0
  1. using Microsoft.VisualBasic;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using System.Data;
  6. using System.Diagnostics;
  7. public class Form1
  8. {
  9.  
  10.     System.Data.Odbc.OdbcConnection cn = new System.Data.Odbc.OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=shreyas; User=root;Password=;");
  11.     System.Data.Odbc.OdbcCommand cmd;
  12.     System.Data.Odbc.OdbcDataAdapter adp;
  13.  
  14.     DataSet ds = new DataSet();
  15.     private void Form1_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e)
  16.     {
  17.         cn.Close();
  18.     }
  19.  
  20.  
  21.     private void Form1_Load(System.Object sender, System.EventArgs e)
  22.     {
  23.         // Fill the data grid viewer
  24.         cn.Open();
  25.         cmd = new System.Data.Odbc.OdbcCommand("Select * from trial1", cn);
  26.         adp = new System.Data.Odbc.OdbcDataAdapter(cmd);
  27.         adp.Fill(ds, "trial1");
  28.         this.DataGridView1.DataSource = ds;
  29.         this.DataGridView1.DataMember = "trial1";
  30.  
  31.     }
  32.  
  33.     private void Button1_Click(System.Object sender, System.EventArgs e)
  34.     {
  35.         //Update records using a Command Builder
  36.         // The variable i gives the number of records updated
  37.         System.Data.Odbc.OdbcCommandBuilder cmdbuilder = new System.Data.Odbc.OdbcCommandBuilder(adp);
  38.         int i = 0;
  39.         try {
  40.             i = adp.Update(ds, "trial1");
  41.             Interaction.MsgBox("Records Updated= " + i);
  42.         } catch (Exception ex) {
  43.             Interaction.MsgBox(ex.Message);
  44.         }
  45.     }
  46.     public Form1()
  47.     {
  48.         Load += Form1_Load;
  49.         FormClosing += Form1_FormClosing;
  50.     }
  51.  
  52.  
  53. }
Add Comment
Please, Sign In to add comment