asp.net access添加返回自遞增id的實(shí)現(xiàn)方法第1/3頁
更新時(shí)間:2008年08月07日 23:26:52 作者:
今天花了一點(diǎn)時(shí)間研究了這個問題,除此之外,還順帶研究了小孔子cms添加數(shù)據(jù)的過程,access添加返回自遞增id也是從小孔子cms中研究出來的。
先看界面:

添加后數(shù)據(jù)庫:

而所要執(zhí)行的語句:
string name_ = this.tbxUseName.Text.Trim();
string webname_ = this.tbxWebName.Text.Trim();
string url_ = this.tbxUrl.Text.Trim();
AddFieldItem("news_Title", name_);
AddFieldItem("news_Source",webname_);
AddFieldItem("news_Anthor",url_);
common.salert("添加成功,添加后的ID為" + insert("db_news").ToString());
當(dāng)我看完小孔子cms對插入數(shù)據(jù)的處理后,自我感覺.net水平還一直停留在asp中。下面結(jié)合代碼講講:
需要說明的是,小孔子cms在插入時(shí)使用的是多層架構(gòu),而這篇文章主要著重講解的是學(xué)習(xí),所以我就沒弄成多層的了。插入時(shí)采用了參數(shù)化的過程,類似sql的存儲過程;在實(shí)際應(yīng)用中插入數(shù)據(jù)十分簡單,正如上面代碼所顯示的。
先講一個類[DbKeyItem]:
/// <summary>
/// 數(shù)據(jù)表中的字段屬性:字段名,字段值
/// </summary>
public class DbKeyItem
{
/// <summary>
/// 字段名稱
/// </summary>
public string fieldName;
/// <summary>
/// 字段值
/// </summary>
public string fieldValue;
public DbKeyItem(string _fieldName, object _fieldValue)
{
this.fieldName = _fieldName;
this.fieldValue = _fieldValue.ToString();
}
}
這個類包含兩個屬性:
1、fieldName:字段名
2、fieldValue:字段值
這個類主要用于:
protected ArrayList alFieldItems = new ArrayList(10);
/// <summary>
/// 添加一個字段/值對到數(shù)組中
/// </summary>
public void AddFieldItem(string _fieldName, object _fieldValue)
{
_fieldName = "[" + _fieldName + "]";
//遍歷看是否已經(jīng)存在字段名
for (int i = 0; i < this.alFieldItems.Count; i++)
{
if (((DbKeyItem)this.alFieldItems[i]).fieldName == _fieldName)
{
throw new ArgumentException("字段已經(jīng)存在");
}
}
this.alFieldItems.Add(new DbKeyItem(_fieldName, _fieldValue));
}

添加后數(shù)據(jù)庫:
而所要執(zhí)行的語句:
復(fù)制代碼 代碼如下:
string name_ = this.tbxUseName.Text.Trim();
string webname_ = this.tbxWebName.Text.Trim();
string url_ = this.tbxUrl.Text.Trim();
AddFieldItem("news_Title", name_);
AddFieldItem("news_Source",webname_);
AddFieldItem("news_Anthor",url_);
common.salert("添加成功,添加后的ID為" + insert("db_news").ToString());
當(dāng)我看完小孔子cms對插入數(shù)據(jù)的處理后,自我感覺.net水平還一直停留在asp中。下面結(jié)合代碼講講:
需要說明的是,小孔子cms在插入時(shí)使用的是多層架構(gòu),而這篇文章主要著重講解的是學(xué)習(xí),所以我就沒弄成多層的了。插入時(shí)采用了參數(shù)化的過程,類似sql的存儲過程;在實(shí)際應(yīng)用中插入數(shù)據(jù)十分簡單,正如上面代碼所顯示的。
先講一個類[DbKeyItem]:
復(fù)制代碼 代碼如下:
/// <summary>
/// 數(shù)據(jù)表中的字段屬性:字段名,字段值
/// </summary>
public class DbKeyItem
{
/// <summary>
/// 字段名稱
/// </summary>
public string fieldName;
/// <summary>
/// 字段值
/// </summary>
public string fieldValue;
public DbKeyItem(string _fieldName, object _fieldValue)
{
this.fieldName = _fieldName;
this.fieldValue = _fieldValue.ToString();
}
}
這個類包含兩個屬性:
1、fieldName:字段名
2、fieldValue:字段值
這個類主要用于:
復(fù)制代碼 代碼如下:
protected ArrayList alFieldItems = new ArrayList(10);
/// <summary>
/// 添加一個字段/值對到數(shù)組中
/// </summary>
public void AddFieldItem(string _fieldName, object _fieldValue)
{
_fieldName = "[" + _fieldName + "]";
//遍歷看是否已經(jīng)存在字段名
for (int i = 0; i < this.alFieldItems.Count; i++)
{
if (((DbKeyItem)this.alFieldItems[i]).fieldName == _fieldName)
{
throw new ArgumentException("字段已經(jīng)存在");
}
}
this.alFieldItems.Add(new DbKeyItem(_fieldName, _fieldValue));
}
您可能感興趣的文章:
- ASP.NET 連接ACCESS數(shù)據(jù)庫的簡單方法
- asp.net中獲取新增加記錄的ID Access版
- asp.net訪問Access數(shù)據(jù)庫溢出錯誤
- asp.net(C#) Access 數(shù)據(jù)操作類
- asp.net 數(shù)據(jù)庫備份還原(sqlserver+access)
- asp.net和asp下ACCESS的參數(shù)化查詢
- ACCESS的參數(shù)化查詢,附VBSCRIPT(ASP)和C#(ASP.NET)函數(shù)
- ASP.net(c#)用類的思想實(shí)現(xiàn)插入數(shù)據(jù)到ACCESS例子
- ASP.NET 鏈接 Access 數(shù)據(jù)庫路徑問題最終解決方案
- ASP.NET連接 Access數(shù)據(jù)庫的幾種方法
相關(guān)文章
ASP.NET MVC API 接口驗(yàn)證的示例代碼
本篇文章主要介紹了ASP.NET MVC API 接口驗(yàn)證的示例代碼,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-10-10
Asp.net 文件上傳類(取得文件后綴名,保存文件,加入文字水印)
Asp.net 取得文件后綴名,保存文件,加入文字水印的代碼類2008-11-11
.NET程序性能監(jiān)控系統(tǒng)Elastic?AMP的使用方法
這篇文章介紹了.NET程序性能監(jiān)控系統(tǒng)Elastic?AMP的使用方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2021-11-11
.NET 下運(yùn)用策略模式(組合行為和實(shí)體的一種模式)
我簡單的理解策略模式就是把行為(方法)單獨(dú)的抽象出來,并采用組合(Has-a)的方式,來組合行為和實(shí)體的一種模式比如,.NET中對數(shù)組排序的Sort的方法就是一個策略模式的實(shí)現(xiàn)模板2012-12-12
.NET+JS對用戶輸入內(nèi)容進(jìn)行字?jǐn)?shù)提示功能的實(shí)例代碼
.NET+JS對用戶輸入內(nèi)容進(jìn)行字?jǐn)?shù)提示功能的實(shí)例代碼,需要的朋友可以參考一下2013-06-06

