資料庫操縱經典類 C

2021-04-06 15:43:18 字數 2672 閱讀 8007

using system;

using system.collections;

using system.collections.specialized;

using system.runtime.remoting.messaging;

using system.data;

using system.data.sqlclient;

using system.configuration;

namespace ltp.sqlserverdal

catch(system.data.sqlclient.sqlexception e)

}    }}

///

/// 執行兩條sql語句,實現資料庫事務。

///

///

///

public static void executesqltran(string sqlstring1,string sqlstring2)

catch(system.data.sqlclient.sqlexception e)

finally }

} ///

/// 執行多條sql語句,實現資料庫事務,每條語句以「;」分割。

///

///

public static void executesqltran(string sqlstringlist)

);foreach (string strsql in split)

}       

tx.commit();     

}catch(system.data.odbc.odbcexception e)}}

///

/// 執行帶乙個儲存過程引數的的sql語句。

///

///

///

///

public static int executesql(string sqlstring,string content)

catch(system.data.sqlclient.sqlexception e)

finally }

}  ///

/// 向資料庫裡插入影象格式的字段

///

///

///

///

public static int executesqlinsertimg(string strsql,byte fs)

catch(system.data.sqlclient.sqlexception e)

finally }

}///

/// 執行一條計算查詢結果語句,返回查詢結果(整數)。

///

///

///

public static int getcount(string strsql)

result.close();    

return i;

}catch(system.data.sqlclient.sqlexception e)

finally}} 

///

/// 執行一條計算查詢結果語句,返回查詢結果(object)。

///

///

///

public static object getsingle(string sqlstring)

else

}catch(system.data.sqlclient.sqlexception e)

finally}}

///

/// 執行查詢語句,返回sqldatareader

///

///

///

public static sqldatareader executereader(string strsql)

catch(system.data.sqlclient.sqlexception e)

finally }

}  ///

/// 執行查詢語句,返回dataset

///

///

///

public static dataset query(string sqlstring)

catch(system.data.sqlclient.sqlexception ex)

return ds;}}

#region 儲存過程操作

///

/// 執行儲存過程

///

///

///

///

public static sqldatareader runprocedure(string storedprocname, idataparameter parameters )

}private static sqlcommand buildquerycommand(sqlconnection connection,string storedprocname, idataparameter parameters)

return command;

}  public static dataset runprocedure(string storedprocname, idataparameter parameters, string tablename )

}#endregion }}

csharp操縱access資料庫類

static string conn provider microsoft.jet.oledb.4.0 data source c tb taizhan.mdb public static int excutenonquery string strsqlcomm catch exception er...

在C 中操縱Oracle資料庫

oracle資料庫相關操作 定義使用者 sql connect sys oracle as sysdba sql create user sa identified by sa sql grant dba to sa sql connect sa sa 定義表 sql create table te...

資料庫操縱語言DML

資料庫操縱語言dml dml 有三條語句 insert update delete.一 insert 插入資料 1 插入一條資料 insert into 表名 列名 values 值列表 insert into stuinfo stuname,stuno,stu stuage,stuaddress ...