Heb de tabel: " DataTable m_dtgebruiker" nodig die in de classe: DBBoek staat.De classe die deze classe aanroept , heet: Boek_controller. En heb dat op deze manier gedaan:
class Boek_controller : DBBoek.
Maar nog krijg ik de foutmeling:
"Error 2 'DatabaseExample2.DBBoek.m_dtgebruiker' is inaccessible due to its protection level C:\Users\savant\Documents\Visual Studio 2008\Projects\DatabaseExample2\DatabaseExample2\Boek_controller.cs 56 18 DatabaseExamp2".
De classe Boek_controller:
de classe: DBBoek:
Dan heb ik ook nog een configuratieFIle, waar de standaardinstellingen van de database staan, zoals bij PHP een config file:
class Boek_controller : DBBoek.
Maar nog krijg ik de foutmeling:
"Error 2 'DatabaseExample2.DBBoek.m_dtgebruiker' is inaccessible due to its protection level C:\Users\savant\Documents\Visual Studio 2008\Projects\DatabaseExample2\DatabaseExample2\Boek_controller.cs 56 18 DatabaseExamp2".
De classe Boek_controller:
Code:
using DatabaseExample2;
using DatabaseExample2.Properties;
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;
//using System.Data.OleDb.OleDbConnection;
using System.Configuration;
using System.Collections;
namespace DatabaseExample2
{
class Boek_controller : DBBoek
{
DBBoek dbBoek = new DBBoek();
Boek boek = new Boek();
Config config = new Config();
Boek_controller boek_controller = new Boek_controller();
//DataTable m_dtgebruiker = new DataTable();
OleDbConnection m_cnADONewConnection = new OleDbConnection();
OleDbDataAdapter m_daDataAdapter = new OleDbDataAdapter();
int m_rowPosition = 0;
//DataTable m_dtContacts = new DataTable();
public Boek_controller()
{
DBBoek dbBoek = new DBBoek();
dbBoek.functie();
//InitializeComponent();
}
private void fclsMain_Closed(object sender, System.EventArgs e)
{
m_cnADONewConnection.Close();
}
private void ShowCurrentRecord()
{
//DataTable m_dtgebruiker();
//dbBoek.functie();
if ( m_dtgebruiker.Rows.Count == 0)
{
boek.txtContactname.Text = "";
boek.txtState.Text = "";
return;
}
boek.txtContactname.Text = m_dtgebruiker.Rows[m_rowPosition]["gebruikersnaam"].ToString();
boek.txtState.Text = m_dtgebruiker.Rows[m_rowPosition]["wachtwoord"].ToString();
}
private void btnMoveFirst_Click(object sender, System.EventArgs e)
{
m_rowPosition = 0;
this.ShowCurrentRecord();
}
private void btnSave_Click(object sender, System.EventArgs e)
{
//DataTable m_dtgebruiker ();
if (!(m_dtgebruiker.Rows.Count == 0))
{
m_dtgebruiker.Rows[m_rowPosition]["gebruikersnaam"] = boek.txtContactname.Text;
m_dtgebruiker.Rows[m_rowPosition]["wachtwoord"] = boek.txtState.Text;
//m_daDataAdapter.Update(m_dtgebruiker);
}
}
public void opslaan()
{
//DataTable m_dtgebruiker;
DataRow drNewRow = m_dtgebruiker.NewRow();
drNewRow["gebruikersnaam"] = boek.txtNewContactName.Text;
drNewRow["wachtwoord"] = boek.txtNewState.Text;
m_dtgebruiker.Rows.Add(drNewRow);
m_daDataAdapter.Update(m_dtgebruiker);
m_rowPosition = m_dtgebruiker.Rows.Count - 1;
this.ShowCurrentRecord();
}
}
}
de classe: DBBoek:
Code:
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;
//using System.Data.OleDb.OleDbConnection;
using System.Configuration;
using System.Collections;
//using System.DBBoek;
namespace DatabaseExample2
{
class DBBoek
{
// DBBoek dbBoek = new DBBoek();
DataTable m_dtgebruiker = new DataTable();
OleDbConnection m_cnADONewConnection = new OleDbConnection();
OleDbDataAdapter m_daDataAdapter = new OleDbDataAdapter();
Config config = new Config();
public DBBoek()
{
DBBoek dbBoek = new DBBoek();
//dbBoek.m_dtgebruiker();
//DataTable m_dtgebruiker = new DataTable();
Config config = new Config();
OleDbDataAdapter m_daDataAdapter = new OleDbDataAdapter();
Boek_controller boek_controller = new Boek_controller();
}
private void fclsMain_Load(object sender, System.EventArgs e)
{
m_cnADONewConnection.ConnectionString =
@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\meetSysteem.mdb";
m_daDataAdapter =
new OleDbDataAdapter("Select * From gebruiker", m_cnADONewConnection);
OleDbCommandBuilder m_cbCommandBuilder = new OleDbCommandBuilder(m_daDataAdapter);
m_daDataAdapter.Fill(m_dtgebruiker);
//this.ShowCurrentRecord();
}
private void fclsMain_Closed(object sender, System.EventArgs e)
{
m_cnADONewConnection.Close();
}
public void functie()
{
DBBoek dbBoek = new DBBoek();
//dbBoek.m_dtgebruiker();
}
private void hallo()
{
throw new NotImplementedException();
}
}
}
Dan heb ik ook nog een configuratieFIle, waar de standaardinstellingen van de database staan, zoals bij PHP een config file:
Code:
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;
//using System.Data.OleDb.OleDbConnection;
using System.Configuration;
using System.Collections;
namespace DatabaseExample2
//namespace DotNetSmart.CodeSamples.MsAccess
{
public class Config
{
//OleDbConnection m_cnADONewConnection = new OleDbConnection();
OleDbDataAdapter m_daDataAdapter = new OleDbDataAdapter();
//OleDbConnection m_cnADONewConnection = new OleDbConnection();
OleDbCommandBuilder m_cbCommandBuilder;//verwerkt het:updaten, inserting&deleting data.
//DataTable m_dtkast = new DataTable();
//int m_rowPosition = 0;
/// An Ms Access OleDBConnection
///
public static System.Data.OleDb.OleDbConnection m_cnADONewConnection()
{
OleDbConnection m_cnADONewConnection = new OleDbConnection("File Name =C:\\meetSysteem.mdb ");
try
{
m_cnADONewConnection.Open();
if (m_cnADONewConnection.State == ConnectionState.Open)
Console.WriteLine("Connection opened successfully!");
else
Console.WriteLine("Connection could not be established");
//return new SqlCommand();
return m_cnADONewConnection;
}
catch (Exception ex)
{
Console.WriteLine(ex.Message.ToString());
//return new SqlCommand();
return m_cnADONewConnection;
}
finally
{
m_cnADONewConnection.Close();
}
Console.ReadLine();
//return;
//retrieve the conenction string from the ConnectionString Key in Web.Config
// string connectionString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionString"];
//create a new OleDB connection
//System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Savant\My Documents\ULeiden\meetSysteem.mdb");
//m_cnADONewConnection.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\Savant\My Documents\ULeiden\meetSysteem.mdb";
//m_cnADONewConnection.Open();
//OleDbConnection.Open();
//Open the connection
//conn.Open();
//return the connection
//return conn;
}
}
}