Autor Beitrag
Rakeem
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Mo 28.02.11 18:42 
Hi,
ich möchte mit OleDbReader etwas aus einer Access DB in einem Datagridview anzeigen lassen.

Bsp

Tabellen Name Neu

Spalten Id,Name
Row 1 ,Karl

komme da aber nicht weiter

ausblenden volle Höhe C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;

namespace WindowsFormsApplication1
{
    public partial class Form1 : Form
    {
        OpenFileDialog pfad = new OpenFileDialog();
        DataSet datenbank;
        public Form1()
        {
            InitializeComponent();
        }

        private void btnÖffnen_Click(object sender, EventArgs e)
        {
            pfad.ShowDialog();
        }
        private void btnVerbunden_Click(object sender, EventArgs e)
        {
            try
            {
                OleDbConnection con = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + pfad.FileName);
                con.Open();
                MessageBox.Show("Datenbank ist verbunden");
            }
            catch (Exception)
            {
                MessageBox.Show("Datenbank ist nicht verbunden");
            }
            finally
            {
            }
            OleDbCommand cmd = new OleDbCommand();
            OleDbDataReader daten = cmd.ExecuteReader();
            cmd.CommandText = "SELECT * FROM [NEU]";
        }
    }
}
Ivy
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 228



BeitragVerfasst: Di 01.03.11 14:36 
was genau geht nicht?
ich habe es bei mir so gelöst:

ausblenden C#-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
public OdbcDataReader Reader;
    public OdbcConnection oConn;
    public OdbcCommand oCmd;
    public DataTable dt;

try
        {
            oConn = new OdbcConnection();
            oConn.ConnectionString = @"Driver={Microsoft dBase Driver (*.dbf)};SourceType=DBF;SourceDB=D:\....;Exclusive=No; Collate=Machine;NULL=NO;DELETED=NO;Extended Properties=dBASE IV;User ID=;Password=";
            oConn.Open();
            oCmd = oConn.CreateCommand();
           oCmd.CommandText = @"SELECT * FROM";
            dt = new DataTable();
            dt.Load(oCmd.ExecuteReader());
            oConn.Close();
         dgvData.DataSource = dt;  //dein DataGridview 

            
        }
        catch (Exception ex)
        {
            MessageBox.Show("Error : " + ex.Message);
            //connectection failed
            return false;
        }//try-catch     
        //connection ok!
        return true;
    }
Rakeem Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 27



BeitragVerfasst: Mi 02.03.11 16:54 
danke fürs helfen hatte es aber schon selbst geschaft