Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. DataBinding and displaying it in a datagrid :along with Code i have written

DataBinding and displaying it in a datagrid :along with Code i have written

Scheduled Pinned Locked Moved C#
databasehelpgraphics
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • T Offline
    T Offline
    Trustapple
    wrote on last edited by
    #1

    Hi Friends, May be this will help you guys to help me :). I have in the form a textbox,a enter button and datagrid. I want to enter data into my DB Table named "Self" on the click of button "Enter". Till there its working fine. Now on form load am trying to display the contents in my database (for simlicity i have only one coloumn in my database:"Name") in a datagrid. The problem am facing is in writting that part of the code. Shown below is my code.Please correct me. private void Form1_Load(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection(); con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Selftest.mdb"; OleDbCommand cmd = new OleDbCommand(); cmd.CommandText = "select * from Self"; cmd.Connection = con; OleDbDataAdapter adap = new OleDbDataAdapter(); adap.SelectCommand = cmd; DataSet ds = new DataSet(); adap.Fill(ds); } Now i will display my entire code if it might help. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using System.Data.Odbc; using System.IO; namespace My_self_Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection(); con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Selftest.mdb"; con.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "Insert into Self(Name) values ('" + txtName.Text + "')"; cmdObj.Connection = con; cmdObj.ExecuteNonQuery(); } private void txtDisplay_Click(object sender, EventArgs e) { } private void gridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void Form1_Load(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection(); con.Conn

    S 1 Reply Last reply
    0
    • T Trustapple

      Hi Friends, May be this will help you guys to help me :). I have in the form a textbox,a enter button and datagrid. I want to enter data into my DB Table named "Self" on the click of button "Enter". Till there its working fine. Now on form load am trying to display the contents in my database (for simlicity i have only one coloumn in my database:"Name") in a datagrid. The problem am facing is in writting that part of the code. Shown below is my code.Please correct me. private void Form1_Load(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection(); con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Selftest.mdb"; OleDbCommand cmd = new OleDbCommand(); cmd.CommandText = "select * from Self"; cmd.Connection = con; OleDbDataAdapter adap = new OleDbDataAdapter(); adap.SelectCommand = cmd; DataSet ds = new DataSet(); adap.Fill(ds); } Now i will display my entire code if it might help. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.OleDb; using System.Data.Odbc; using System.IO; namespace My_self_Test { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void button1_Click(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection(); con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\My Documents\Selftest.mdb"; con.Open(); OleDbCommand cmdObj = new OleDbCommand(); cmdObj.CommandText = "Insert into Self(Name) values ('" + txtName.Text + "')"; cmdObj.Connection = con; cmdObj.ExecuteNonQuery(); } private void txtDisplay_Click(object sender, EventArgs e) { } private void gridView_CellContentClick(object sender, DataGridViewCellEventArgs e) { } private void Form1_Load(object sender, EventArgs e) { OleDbConnection con = new OleDbConnection(); con.Conn

      S Offline
      S Offline
      Sourie
      wrote on last edited by
      #2

      I have written like this and this works: dbConnetion1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db.mdb"; dbConnetion1.Open(); oleDbCommand1.CommandText = "select * from Name"; oleDbCommand1.CommandType = CommandType.Text; oleDbCommand1.Connection = dbConnetion1; oleDbCommand1.ExecuteNonQuery(); oleDbDataAdapter1.SelectCommand = oleDbCommand1; DataTable table1 = new DataTable(); oleDbDataAdapter1.Fill(table1); dataGridView1.DataSource = table1; //or this one DataSet dataset1 = new DataSet(); oleDbDataAdapter1.Fill(dataset1, "Name"); dataGridView2.DataSource = dataset1; dataGridView2.DataMember = "Name"; dbConnetion1.Close();

      Sourie

      T 1 Reply Last reply
      0
      • S Sourie

        I have written like this and this works: dbConnetion1.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\db.mdb"; dbConnetion1.Open(); oleDbCommand1.CommandText = "select * from Name"; oleDbCommand1.CommandType = CommandType.Text; oleDbCommand1.Connection = dbConnetion1; oleDbCommand1.ExecuteNonQuery(); oleDbDataAdapter1.SelectCommand = oleDbCommand1; DataTable table1 = new DataTable(); oleDbDataAdapter1.Fill(table1); dataGridView1.DataSource = table1; //or this one DataSet dataset1 = new DataSet(); oleDbDataAdapter1.Fill(dataset1, "Name"); dataGridView2.DataSource = dataset1; dataGridView2.DataMember = "Name"; dbConnetion1.Close();

        Sourie

        T Offline
        T Offline
        Trustapple
        wrote on last edited by
        #3

        Thank You Sourie. It works. Thanks a lot :)

        S 1 Reply Last reply
        0
        • T Trustapple

          Thank You Sourie. It works. Thanks a lot :)

          S Offline
          S Offline
          Sourie
          wrote on last edited by
          #4

          Welcome. I have found a manual in this area. It is helpful. If you want it please tell me: mansureh_shahraki@yahoo.com

          Sourie

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups