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. Using DataGrid with OleDB

Using DataGrid with OleDB

Scheduled Pinned Locked Moved C#
helpquestion
5 Posts 3 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.
  • H Offline
    H Offline
    Hoang Dung
    wrote on last edited by
    #1

    I'm use an OleDbDataReader variable for get data from OLAP cube. I want show this data to DataGrid control, but I don't know a way. Can you help me? Thanks.

    D K 2 Replies Last reply
    0
    • H Hoang Dung

      I'm use an OleDbDataReader variable for get data from OLAP cube. I want show this data to DataGrid control, but I don't know a way. Can you help me? Thanks.

      D Offline
      D Offline
      dynamic
      wrote on last edited by
      #2

      here's an example of adding data from a database to a datagrid ( using an OleDbConnection ) VbCode:


      Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click   
           Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:/bin.mdb"   
           Dim strCommand As String = "SELECT \* FROM binFrm"   
           OpenAccess(strConnection, strCommand)   
       End Sub   
      
       Public Function OpenAccess(ByVal strConn As String, ByVal strComm As String)   
           Dim DBCon As New OleDbConnection(strConn)   
           DBCon.Open()   
           Dim DBCommand As New OleDbCommand(strComm, DBCon)   
           Dim DBAdapt As OleDbDataAdapter   
           DBAdapt = New OleDbDataAdapter(DBCommand)   
           Dim DBset As New DataSet()   
           DBAdapt.Fill(DBset, "binFrm")   
           DataGrid1.DataSource = DBset.Tables("binFrm") '///add the tabel "binfrm" to the datagrid   
           DBCon.Close()   
           DBCommand.Dispose()   
           DBAdapt.Dispose()   
           DBset.Dispose()   
       End Function   
      

      not sure if that's what your after , but hope it helps :) Vb:


      Public Function TwinsOnWay(ByVal twins As String) As String
      Se

      D 1 Reply Last reply
      0
      • D dynamic

        here's an example of adding data from a database to a datagrid ( using an OleDbConnection ) VbCode:


        Private Sub Button1\_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click   
             Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:/bin.mdb"   
             Dim strCommand As String = "SELECT \* FROM binFrm"   
             OpenAccess(strConnection, strCommand)   
         End Sub   
        
         Public Function OpenAccess(ByVal strConn As String, ByVal strComm As String)   
             Dim DBCon As New OleDbConnection(strConn)   
             DBCon.Open()   
             Dim DBCommand As New OleDbCommand(strComm, DBCon)   
             Dim DBAdapt As OleDbDataAdapter   
             DBAdapt = New OleDbDataAdapter(DBCommand)   
             Dim DBset As New DataSet()   
             DBAdapt.Fill(DBset, "binFrm")   
             DataGrid1.DataSource = DBset.Tables("binFrm") '///add the tabel "binfrm" to the datagrid   
             DBCon.Close()   
             DBCommand.Dispose()   
             DBAdapt.Dispose()   
             DBset.Dispose()   
         End Function   
        

        not sure if that's what your after , but hope it helps :) Vb:


        Public Function TwinsOnWay(ByVal twins As String) As String
        Se

        D Offline
        D Offline
        dynamic
        wrote on last edited by
        #3

        oops that the vb.net version lol , i'll try to bung a C# version together Vb:


        Public Function TwinsOnWay(ByVal twins As String) As String
        Select Case twins
        Case "Gender"
        Return "Two Girls"
        End Select
        End Function


        D 1 Reply Last reply
        0
        • D dynamic

          oops that the vb.net version lol , i'll try to bung a C# version together Vb:


          Public Function TwinsOnWay(ByVal twins As String) As String
          Select Case twins
          Case "Gender"
          Return "Two Girls"
          End Select
          End Function


          D Offline
          D Offline
          dynamic
          wrote on last edited by
          #4

          here ya go , this time in C# lol , hope it helps VbCode:


          private void button1_Click(object sender, System.EventArgs e)
          {
          string strConnection="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + "C:/bin.mdb";
          string strCommand = "SELECT * FROM binFrm";
          OpenAccess(strConnection, strCommand);
          }

          public void OpenAccess(string Connection, string Command)
          {
          OleDbConnection DBCon=new OleDbConnection(Connection);
          DBCon.Open();
          OleDbCommand DBCommand=new OleDbCommand(Command, DBCon);
          OleDbDataAdapter DBAdapt=new OleDbDataAdapter(DBCommand);
          DataSet DBset=new DataSet();
          DBAdapt.Fill(DBset, "binFrm");
          dataGrid1.DataSource=DBset.Tables["binFrm"];
          DBCon.Close();
          DBCommand.Dispose();
          DBAdapt.Dispose();
          DBset.Dispose();

          }   
          

          :) Vb:


          Public Function TwinsOnWay(ByVal twins As String) As String
          Select Case twins
          Case "Gender"
          Return "Two Girls"
          End Select
          End Function


          1 Reply Last reply
          0
          • H Hoang Dung

            I'm use an OleDbDataReader variable for get data from OLAP cube. I want show this data to DataGrid control, but I don't know a way. Can you help me? Thanks.

            K Offline
            K Offline
            Khang Nguyen
            wrote on last edited by
            #5

            Hoang Dung, the following is not the best code on the globe but hope it gives you some ideas. // construct table for Tasks grid and define columns m_dtTasks = new DataTable("Tasks"); m_dtTasks.Columns.Add("Task Name", typeof(string)); m_dtTasks.Columns.Add("Frame Maker Location", typeof(string)); m_dtTasks.Columns.Add("Approved", typeof(string)); m_dtTasks.Columns.Add("Approval Cycle", typeof(string)); OleDbCommand cmd = new OleDbCommand(sSelectQuery, conn); // have yr query & connection ready OleDbDataReader reader = cmd.ExecuteReader(); // DataReader is now loaded with data while(reader.Read()) { nNumRowsAffected++; Console.WriteLine("TaskName = " + reader.GetString(0)); sTaskName = reader.GetString(0); // TaskName sFrameMakerLoc = reader.GetString(3); // FrameMakerLocation sApproved = (reader.GetBoolean(11) ? "Y" : "N"); // Status sApprovalCycle = reader.GetString(12); // Approval_Cycle // construct a new data row drTask = dtTasks.NewRow(); drTask["Task Name"] = sTaskName; drTask["Frame Maker Location"] = sFrameMakerLoc; drTask["Approved"] = sApproved; drTask["Approval Cycle"] = sApprovalCycle; // add new row to table dtTasks.Rows.Add(drTask); } dgdTask.DataSource = dtTasks; // attach data source to grid Hope it helps Khang Nguyen ;)

            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