2014-10-10 65 views
0

使用Databaselaag不起作用,我已經完成了所有這些步驟http://www.c-sharpcorner.com/UploadFile/b8d90a/connect-oledb-database-in-C-Sharp-in-easy-steps/C#錯誤:無法找到類型或命名空間名稱',檢查框架

我想連接一個MS Acces數據庫與我的Windows應用程序。所有這些框架4客戶端配置文件

類型或命名空間名稱「Databaselaag」找不到(是否缺少using指令或程序集引用?)

是錯誤即時得到,在使用Databaselaag;在我的第二個代碼不能被發現被我不知道爲什麼......

這裏是我的數據庫代碼

using System; 
using System.Collections.Generic; 
using System.Text; 
using System.Data; 
using System.Data.OleDb; 

namespace Databaselaag 

{ 

public class DBaccess 
{ 

private static string connectionstr; 

static DBaccess() 
{ 
    string mdffile; 
    mdffile = @"C:\Users\rik\Documents\Visual Studio 2010\Projects\Week-2-Opdracht\Database\Clienten.accdb"; 

    connectionstr = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + mdffile + "'"; 


} 

public static DataSet Getwaardenquery(string sqlstr) 
{ 
    DataSet ds = new DataSet(); 
    Console.WriteLine(sqlstr); 
    OleDbConnection con = new OleDbConnection(connectionstr); 

    OleDbDataAdapter dap = new OleDbDataAdapter(sqlstr, con); 
    dap.Fill(ds); 
    return ds; 

} 

public static int Uitvoerenquery(string sqlstr) 
{ 
    int resultaat = -1; 
    Console.WriteLine(sqlstr); 

    OleDbConnection con = new OleDbConnection(connectionstr); 
    OleDbCommand cmd = new OleDbCommand(sqlstr, con); 

    try 
    { 
     con.Open(); 
     resultaat = cmd.ExecuteNonQuery(); 
    } 
    catch (Exception exp) 
    { 
     string x = exp.Message; 
    } 
    finally 
    { 
     if (con.State == ConnectionState.Open) 
     { 
      con.Close(); 
     } 
    } 
    return resultaat; 
} 

} 

,這是Clienten代碼,我要對數據庫使用此代碼

鏈接
using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Text; 
using Week_2_Opdracht_MODEL; 
using System.Data.OleDb; 
using System.Data; 
using Databaselaag; 


namespace Week_2_Opdracht_MODEL 
{ 
public class Clienten 
{ 
public static List<Client> _clientenlijst = new List<Client>(); 

public Clienten() 
{ 
    VulClientObjecten(); 
} 

//maak dummy gegevens aan 
public static void VulClientObjecten() 
{ 
    Client client; 

    int i; 
    for (i = 1; i <= 25; i++) 
    { 
     client = new Client(
      /* "Nummer */i, 
      "Voornaam", 
      "Achternaam", 
      /* man/vrouw */true, 
      /* leeftijd */25 + (i * 2), 
      "Woonplaats"); 

     _clientenlijst.Add(client); 
    } 
} 

//create 
public static void VoegClientToe(Client client) 
{ 
    _clientenlijst.Add(client); 
} 

//read 
public static Client ZoekClient(int clientNummer) 
{ 
    foreach (Client client in _clientenlijst) 
    { 
     if (client.Nummer == clientNummer) 
     { 
      return client; 
     } 
    } 
    return new Client(); 
} 

//delete 
public static void VerwijderClient(int clientNummer) 
{ 
    Client client = ZoekClient(clientNummer); 
    _clientenlijst.Remove(client); 
    Console.WriteLine(client); 
} 

//update 
public static void UpdateClient(int clientNummer, string voorNaam, string achterNaam, 
           bool geslacht, int leefTijd, string woonPlaats) 
{ 
    VerwijderClient(clientNummer); 

    Client client = new Client(clientNummer, voorNaam, achterNaam, geslacht, leefTijd, woonPlaats); 

    VoegClientToe(client); 


} 



public static void VerwijderClient(int clientNummer, string voorNaam, string achterNaam, 
            bool geslacht, int leefTijd, string woonPlaats) 
{ 
    Client client = ZoekClient(clientNummer); 
    _clientenlijst.Remove(client); 
    Console.WriteLine(client);  
} 
} 

有人知道發生了什麼嗎?

+0

添加了Databaselaag的到你的工作 – vallabha 2014-10-10 08:10:37

+0

洛爾由於當前項目的參考基準,工作 – 2014-10-10 08:14:33

+0

下一步的問題..我得到沒有更多的錯誤,但是當我運行並添加客戶端時,當我打開它時,它們不會添加到我的acces數據庫中。我檢查了所有的行和collums – 2014-10-10 08:25:37

回答

1

您是否在項目中添加了Databaselaag

+0

哈哈!謝謝,花了我幾個小時,你2分鐘 – 2014-10-10 08:14:11

+0

下一個問題..我沒有得到更多的錯誤,但是當我運行並添加客戶端時,他們不會在我的acces數據庫中添加時,我打開它。我檢查了所有的行和collums – 2014-10-10 08:22:57

+0

也許是因爲你永遠不會在Clienten代碼中調用'DBaccess'類... – Orace 2014-10-10 08:31:04

2

你有沒有加入Databaselaag到目前的項目,你的工作

相關問題