C 資料庫操作例項

2021-04-19 08:13:41 字數 2731 閱讀 3519

最近學習了c#,乙個例項程式,對access資料庫的單個表檔案進行操作的例子。其中包括了對資料的查詢,新增,刪除,更新。其中用到的內容總結如下:

(1)程式類劃分:user類----資料類,與資料庫中的myuser表相對應

connectdatabase類-----連線字串生成,負責生成連線字串

manageuser類------負責各項操作事物,包括新增,刪除,查詢,更新等功能的實現

(2)出於練習的目的,採用了listview控制項顯示所有資料。用到了新增,刪除等部分的**。

(3)部分**

connectdatabase類的**:

public class connectdatabase

}

user類的**:

/*

* created by sharpdevelop.

* user: lqbjh

* date: 2008-8-4

* time: 7:02

* * to change this template use tools | options | coding | edit standard headers.

*/using system;

using system.windows.forms;

namespace datamanage

set}

// [property("name")]

public virtual string name

set}

//[property("password")]

public virtual string password

set}

//[property("salary")]

public virtual float salary

set}

//[property("address")]

public virtual string address

set}

//[property("birthday")]

public virtual datetime birthday

set}

//[property("memo")]

public virtual string memo

set}

#endregion

public user()

public user(int id,string name,string password,float salary,string address,datetime birthday,string memo)}}

mangeuser類的**:

/*

* created by sharpdevelop.

* user: lqbjh

* date: 2008-8-4

* time: 7:14

* * to change this template use tools | options | coding | edit standard headers.

*/using system;

using system.data;

using system.data.oledb;

using system.collections;

namespace datamanage

//取得連線

public oledbconnection getconn()

//依據姓名獲得使用者資訊

public user getuserfromname(string searchname)

else

reader.close();//關閉記錄集

oleconn.close();//關閉連線

}catch(exception e)

return tempuser;

}//獲取所有使用者的資訊

public arraylist getalluser()

reader.close();//關閉記錄集

oleconn.close();//關閉連線

}catch(exception e)

return arr;

}public void insertuser(user insertuser)

catch(exception e)

}public void deleteuser(int m_id)

catch(exception e)

}public string getinsertsql(user insertuser)

public string getdelusersql(int m_id)

public string getuserfromnamesql(string name)

public arraylist exeselect(string sqlsel)

reader.close();//關閉記錄集

oleconn.close();//關閉連線

}catch(exception e)

return arr;

}public void exenoquery(string strsql)

else

trycatch(exception e)}}

}

源**http://download.csdn.net/user/jh2005

MySQL資料庫操作例項 C

環境設定 安裝完mysql之後,將安裝目錄中的include目錄下的libmysql.lib檔案拷到vs2008安裝目錄中的vc lib 下,然後在 專案 選項 c c 常規 中的附加包含目錄 以及 鏈結器 常規 中的附加庫目錄中 加入 c mysql include 並且在 鏈結器 輸入 中的附加...

C 中操作SQLite資料庫例項

最近專案中有使用到sqlite資料庫,於是查詢資料,編寫了乙個asp.net基於c 語言的sqlite資料庫操作例項.大家看 就可以看懂了,和以往使用ado.net操作sql 資料庫類似.完畢後,該安裝程式自動在在系統註冊 即可在 新增引用 中看到所安裝的provider 然後,在專案中新增上圖所選...

MySQL資料庫操作例項

由於課程大實驗需要使用c 操作mysql資料庫,經過一番研究終於成功實現vs2008中與mysql的連線。環境設定 安裝完mysql之後,將安裝目錄中的include目錄下的libmysql.lib檔案拷到vs2008安裝目錄中的vc lib 下,然後在 專案 選項 c c 常規 中的附加包含目錄 ...