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. ADO.NET: DataSet, DataGridView

ADO.NET: DataSet, DataGridView

Scheduled Pinned Locked Moved C#
csharpdatabasedesigngame-devhelp
7 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.
  • B Offline
    B Offline
    budidharma
    wrote on last edited by
    #1

    This is my first time trying to work with a database. Let me explain what I've done real quick, then post my code, and you can tell me how I'm retarded. (Please) First, I added an existing database to the project as a new data source. I did not have it automatically generate a typed dataset. Next, in the design window, I added an untyped dataset to my form window. Then I placed a datagridview object in the window. Under the DataGridView properties, I set the datasource to my untyped dataset. I then modified my form code, as so: public partial class PTAnalyzer : Form { // DATA ACCESS CODE public OleDbConnection conn; public OleDbDataAdapter dAdapter; public DataSet dSet; public string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\ptrack6.mdb"; public PTAnalyzer() { InitializeComponent(); // DATA ACCESS INITIALIZATION try { conn = new OleDbConnection(conString); dAdapter = new OleDbDataAdapter("SELECT * FROM game WHERE player_id = 11", conn); dSet = new DataSet(); //refreshes rows in the DataSet dAdapter.Fill(dataSetPT, "game"); } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message); } //try-catch } } No errors, it runs fine. But nothing is displayed within the datagridview object. What am I doing wrong here? Thanks.

    J 1 Reply Last reply
    0
    • B budidharma

      This is my first time trying to work with a database. Let me explain what I've done real quick, then post my code, and you can tell me how I'm retarded. (Please) First, I added an existing database to the project as a new data source. I did not have it automatically generate a typed dataset. Next, in the design window, I added an untyped dataset to my form window. Then I placed a datagridview object in the window. Under the DataGridView properties, I set the datasource to my untyped dataset. I then modified my form code, as so: public partial class PTAnalyzer : Form { // DATA ACCESS CODE public OleDbConnection conn; public OleDbDataAdapter dAdapter; public DataSet dSet; public string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\ptrack6.mdb"; public PTAnalyzer() { InitializeComponent(); // DATA ACCESS INITIALIZATION try { conn = new OleDbConnection(conString); dAdapter = new OleDbDataAdapter("SELECT * FROM game WHERE player_id = 11", conn); dSet = new DataSet(); //refreshes rows in the DataSet dAdapter.Fill(dataSetPT, "game"); } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message); } //try-catch } } No errors, it runs fine. But nothing is displayed within the datagridview object. What am I doing wrong here? Thanks.

      J Offline
      J Offline
      Jared Parsons
      wrote on last edited by
      #2

      budidharma wrote:

      dSet = new DataSet(); //refreshes rows in the DataSet dAdapter.Fill(dataSetPT, "game");

      Did you mean dSet in that last line? Jared Parsons jaredp@beanseed.org http://spaces.msn.com/members/jaredp/

      B 1 Reply Last reply
      0
      • J Jared Parsons

        budidharma wrote:

        dSet = new DataSet(); //refreshes rows in the DataSet dAdapter.Fill(dataSetPT, "game");

        Did you mean dSet in that last line? Jared Parsons jaredp@beanseed.org http://spaces.msn.com/members/jaredp/

        B Offline
        B Offline
        budidharma
        wrote on last edited by
        #3

        Sorry, that dSet isn't actually used. I should delete that line. The data set is "dataSetPT."

        J 1 Reply Last reply
        0
        • B budidharma

          Sorry, that dSet isn't actually used. I should delete that line. The data set is "dataSetPT."

          J Offline
          J Offline
          Jared Parsons
          wrote on last edited by
          #4

          In the code you posted, you didn't hook your adapter up to your DataGridView. Can you post that code? Jared Parsons jaredp@beanseed.org http://spaces.msn.com/members/jaredp/

          B 1 Reply Last reply
          0
          • J Jared Parsons

            In the code you posted, you didn't hook your adapter up to your DataGridView. Can you post that code? Jared Parsons jaredp@beanseed.org http://spaces.msn.com/members/jaredp/

            B Offline
            B Offline
            budidharma
            wrote on last edited by
            #5

            Sure. I'm using VS 2005 rc3. The code was autogenerated by the IDE. Here's the entire two files, most was autogenerated, excluding the stuff I posted in that first post. 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; namespace PTAnalyzer { public partial class PTAnalyzer : Form { // DATA ACCESS CODE public OleDbConnection conn; public OleDbDataAdapter dAdapter; public DataSet dSet; public string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\ptrack6.mdb"; public PTAnalyzer() { InitializeComponent(); // DATA ACCESS INITIALIZATION try { conn = new OleDbConnection(conString); dAdapter = new OleDbDataAdapter("SELECT * FROM game WHERE player_id = 11", conn); dAdapter.Fill(dataSetPT, "game"); } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message); } //try-catch } } } namespace PTAnalyzer { partial class PTAnalyzer { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.dataSetPT = new System.Data.DataSet(); this.dataGridViewResults = new System.Windows.Forms.DataGridView(); ((System.ComponentModel.ISupportInitialize)(this.dataSetPT)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewResults)).BeginInit(); this.SuspendLayout();

            B 1 Reply Last reply
            0
            • B budidharma

              Sure. I'm using VS 2005 rc3. The code was autogenerated by the IDE. Here's the entire two files, most was autogenerated, excluding the stuff I posted in that first post. 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; namespace PTAnalyzer { public partial class PTAnalyzer : Form { // DATA ACCESS CODE public OleDbConnection conn; public OleDbDataAdapter dAdapter; public DataSet dSet; public string conString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=..\\..\\ptrack6.mdb"; public PTAnalyzer() { InitializeComponent(); // DATA ACCESS INITIALIZATION try { conn = new OleDbConnection(conString); dAdapter = new OleDbDataAdapter("SELECT * FROM game WHERE player_id = 11", conn); dAdapter.Fill(dataSetPT, "game"); } catch (Exception ex) { MessageBox.Show("Error : " + ex.Message); } //try-catch } } } namespace PTAnalyzer { partial class PTAnalyzer { /// /// Required designer variable. /// private System.ComponentModel.IContainer components = null; /// /// Clean up any resources being used. /// /// true if managed resources should be disposed; otherwise, false. protected override void Dispose(bool disposing) { if (disposing && (components != null)) { components.Dispose(); } base.Dispose(disposing); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() { this.dataSetPT = new System.Data.DataSet(); this.dataGridViewResults = new System.Windows.Forms.DataGridView(); ((System.ComponentModel.ISupportInitialize)(this.dataSetPT)).BeginInit(); ((System.ComponentModel.ISupportInitialize)(this.dataGridViewResults)).BeginInit(); this.SuspendLayout();

              B Offline
              B Offline
              budidharma
              wrote on last edited by
              #6

              Specifically, in the second file, this is where the datagridview's datasource is set. this.dataGridViewResults.DataSource = this.dataSetPT; Really though, I'm trying to stumble through this and have no idea what I'm doing.

              B 1 Reply Last reply
              0
              • B budidharma

                Specifically, in the second file, this is where the datagridview's datasource is set. this.dataGridViewResults.DataSource = this.dataSetPT; Really though, I'm trying to stumble through this and have no idea what I'm doing.

                B Offline
                B Offline
                budidharma
                wrote on last edited by
                #7

                Finally just figured it out. I had to specifically set the datagridview datasource to a table index contained within the dataset. I was just setting it to the dataset.

                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