C 查詢和插入資料到sql資料庫

2021-07-04 20:07:19 字數 1272 閱讀 2123

連線sql資料庫步驟:

1. vs10 -> tools -> connect to database ->microsoft sql server -> 填寫server name : use sql server authentication (常用方式):select or enter a database name -> ok

2. 在server explorer 中選擇連到的資料庫右鍵選屬性獲取連線字串。

private sqlconnection _getconnection()  

//得到連線物件

catch(exception exception) }

private sqlcommand _getcommand(string sqlstring, sqlconnection sqlconnection) //得到sql命令物件

public string getuidinusers(string username)  

//根據使用者名稱查詢使用者id 

'", username);

sqlconnection sqlconnection = _getconnection();

sqlconnection.open();

object reader = _getcommand(selectsql, sqlconnection).executescalar();

if (reader != null)

sqlconnection.close();

return uid; 

}

private void _writelogs(...parameters);

sqlconnection.insertlog(prams);

}public void insertlog(sqlparameter parm)  

//插入資料

,'','',,...)", parm[0].value, parm[1].value,  

parm[2].value, 

parm[3].value,...);

sqlconnection sqlconnection = _getconnection();

sqlconnection.open();

_getcommand(insertsql, sqlconnection).executenonquery();

_getconnection().close();

}catch (exception exception)

}

ThinkPhp插入資料到資料庫

首先我們在home view目錄下建立乙個add資料夾,然後在add資料夾中建立乙個add.html檔案 我們需在這個檔案中是建立乙個簡單表單,對應我們資料表中的字段 html lang en 在我的資料thinkphp資料庫中有think form資料表,表中的字段為 id,title 第二步 建...

Access 跨資料庫查詢和插入資料

當前資料庫為testa,要查詢資料庫testb中的某個表內容,我們就可以採用如下方法。第一種 select from 表名in testb的路徑 例如 select from qybm in d accessdb testb.mdb 第二種 select from database testb的路徑...

wp insert post 插入文章到資料庫

在 wordpress 主題目錄下的 index.php 檔案中,新增如下 建立文章物件 my post array post title 我的測試文章 post content 這是乙個測試文章。post status publish post author 1,對應作者 id post cate...