daily pastebin goal
66%
SHARE
TWEET

Untitled

a guest Nov 13th, 2018 124 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.Data.OleDb;
  11.  
  12. namespace WindowsFormsApp3
  13. {
  14.     public partial class Form1 : Form
  15.     {
  16.         OleDbDataAdapter DANorthwind;
  17.         OleDbCommandBuilder commandbuilder;
  18.         DataTable DTSuppliers = new DataTable();
  19.         DataRow dtsuppliersRow;
  20.         String Connstr, dbname;
  21.         String sqlstr;
  22.         int rowpos = 0;
  23.  
  24.         public Form1()
  25.         {
  26.             InitializeComponent();
  27.         }
  28.  
  29.         private void btnexit_Click(object sender, EventArgs e)
  30.         {
  31.             Application.Exit();
  32.         }
  33.  
  34.         private void btnnext_Click(object sender, EventArgs e)
  35.         {
  36.             if (rowpos >= DTSuppliers.Rows.Count -1) {
  37.                 return;
  38.             } else
  39.             {
  40.                 rowpos += 1;
  41.             }
  42.             txt1.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Supplier_ID"]);
  43.             txt2.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Company_Name"]);
  44.             if (DTSuppliers.Rows[rowpos]["Phone"] == null)
  45.             {
  46.                 txt3.Text = "NULL";
  47.  
  48.             } else { txt3.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Phone"]);
  49.             }
  50.         }
  51.  
  52.         private void btnlast_Click(object sender, EventArgs e)
  53.         {
  54.             if (rowpos <= 0)
  55.             {
  56.                 return;
  57.             }
  58.             else
  59.             {
  60.                 rowpos -= 1;
  61.             }
  62.             txt1.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Supplier_ID"]);
  63.             txt2.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Company_Name"]);
  64.             if (DTSuppliers.Rows[rowpos]["Phone"] == null)
  65.             {
  66.                 txt3.Text = "NULL";
  67.  
  68.             }
  69.             else
  70.             {
  71.                 txt3.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Phone"]);
  72.             }
  73.  
  74.         }
  75.  
  76.         private void btnupdate_Click(object sender, EventArgs e)
  77.         {
  78.             int changes;
  79.             DANorthwind = new OleDbDataAdapter(sqlstr, Connstr);
  80.             commandbuilder = new OleDbCommandBuilder(DANorthwind);
  81.             changes = DANorthwind.Update(DTSuppliers);
  82.         }
  83.  
  84.         private void CBAuthor_SelectedIndexChanged(object sender, EventArgs e)
  85.         {
  86.             rowpos = CBAuthor.SelectedIndex;
  87.             txt1.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Supplier_ID"]);
  88.             txt2.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Company_Name"]);
  89.             if (DTSuppliers.Rows[rowpos]["Phone"] == null)
  90.             {
  91.                 txt3.Text = "NULL";
  92.             }
  93.             else
  94.             {
  95.                 txt3.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Phone"]);
  96.             }
  97.         }
  98.                
  99.  
  100.         private void Form1_Load(object sender, EventArgs e)
  101.         {            
  102.             this.suppliersTableAdapter.Fill(this.northwindDataSet.Suppliers);
  103.             dbname = "Northwind.mdb";
  104.             Connstr = "Provider=Microsoft.Jet.OLEDB.4.0;" +
  105.                 "Data Source = " + dbname;
  106.             sqlstr = "Select * from Suppliers;";
  107.             DANorthwind = new OleDbDataAdapter(sqlstr, Connstr);
  108.             DANorthwind.Fill(DTSuppliers);
  109.             CBAuthor.DataSource = DTSuppliers;
  110.             CBAuthor.DisplayMember = DTSuppliers.Columns[1].ColumnName;
  111.             CBAuthor.ValueMember = DTSuppliers.Columns[0].ColumnName;
  112.             if (DTSuppliers.Rows.Count > 0)
  113.             {
  114.                 txt1.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Supplier_ID"]);
  115.                 txt2.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Company_Name"]);
  116.                 txt3.Text = Convert.ToString(DTSuppliers.Rows[rowpos]["Phone"]);
  117.             }
  118.  
  119.         }              
  120.                
  121.     }
  122. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top