資料庫的操作

2022-07-17 07:21:12 字數 2161 閱讀 5331

多個資料庫連線,通過不同的連線字串進行連線

public static class _dbcontext

public static modelinfocontext modelinfocontext(string mysqlconnectionstring)

public static nodecontext nodecontext(string mysqlconnectionstring)

public static newigbomcontext newigbomcontext(string mysqlconnectionstring)

}

原生的資料庫連線

/// /// 通用資料庫類mysql 

///

public class class_mysql_conn

//關閉資料庫鏈結

public static void close_conn(mysqlconnection conn)

gc.collect();

}//執行mysql語句

public static int run_sql(string sql, string connstr)

catch (exception e)

}// 生成command物件

public static mysqlcommand create_cmd(string sql, mysqlconnection conn)

// 執行mysql語句返回 datatable

public static datatable get_datatable(string sql, string connstr, string table_name)

// 執行mysql語句返回 mysqldatareader物件

public static mysqldatareader get_reader(string sql, string connstr)

catch

close_conn(conn);

return dr;

}// 執行mysql語句返回 mysqldataadapter物件

public static mysqldataadapter get_adapter(string sql, string connstr)

// 執行mysql語句,返回dataset物件

public static dataset get_dataset(string sql, string connstr, dataset ds)

catch (exception err)

return ds;

}// 執行mysql語句,返回dataset物件

public static dataset get_dataset(string sql, string connstr, dataset ds, string tablename)

catch (exception ex)

return ds;

}// 執行mysql語句,返回dataset物件,將資料進行了分頁

public static dataset get_dataset(string sql, string connstr, dataset ds, int startindex, int pagesize, string tablename)

catch (exception ex)

close_conn(conn);

return ds;

}// 返回mysql語句執行結果的第一行第一列

public static string get_row1_col1_value(string sql, string connstr)

else

}catch

close_conn(conn);

return result;

}}

使用:

/////批量插入造資料:3個建築,3*10個樓層,3*10*1000個牆,3*10*1000*2個窗

資料庫 基礎資料庫的操作

什麼是資料庫 資料庫 database 是按照資料結構來組織 儲存和管理資料的倉庫 常見的資料庫oracle mysql sun db2 ibm sql server microsoft postgre sql 專業術語 資料庫系統 database system dbs 資料庫 database ...

資料庫 MySQL 資料庫的操作

1.建立資料庫 create database if notexists 資料庫名 charset 字元編碼 utf8mb4 如果多次建立會報錯 字元編碼不指定預設 utf8mb4 給資料庫命名 定要習慣性加上反引號,防 和關鍵 字衝突 2.檢視資料庫 show databases 3.選擇資料庫 ...

資料庫的操作

一 ddl資料庫操作庫 1.1 建立資料庫 create database 資料庫名 2 檢視建立的資料庫資料 show create database mydb1 3 指定資料庫字符集 create database mydb2 character set gbk 4 檢視資料庫支援的字符集 sh...