2017 3 2 C 鏈結資料庫實現登陸

2022-04-28 19:42:11 字數 1097 閱讀 4597

實際操作下來,主要是兩種登陸方式:

1.windows的身份驗證;

2.sql sever的身份驗證;

兩種的方法不同,但是主要是通過複製建立資料庫的字串來鏈結;

ado.net提供了sql connection類,呼叫命名空間using system.data.sqlclien來呼叫。

下面就是

//乙個字串

string constring = "data source=ip位址; database=資料庫名;user id=使用者名稱; password=密碼";

//鏈結資料庫

cnn.open();

//下面這個和資料庫之間的內容進行交換對比,之前出現了資料儲存過程問題,其實就是這句話沒有寫好,[login] 這個不加提取號,其實也可以成功提取。

string selectsql = "select * from [login] where username='"+ untextbox1.text+"' and userpassword='"+untextbox2.text+"'";

//建立sqlcommand例項,sqlcommand物件允許你指定在資料庫上執行的操作的型別。對selectsql執行乙個儲存過程(儲存過程一般是作為乙個獨立的部分來執行,而函式可以作為查詢語句的乙個部分來呼叫,由於函式可以返回乙個表物件,因此它可以在查詢語句中位於from關鍵字的後面。)

sqlcommand cmd = new sqlcommand(selectsql, conn);

//兩個的值相等

cmd.commandtype = commandtype.text;

//若要建立 sqldatareader,必須呼叫 sqlcommand 物件的 executereader 方法,而不要直接使用建構函式。讀取行只進流。

sqldatareader sdr;

//executereader()盡可能快地對資料庫進行查詢並得到結果。executereader 返回乙個datareader物件:如果在sqlcommand物件中呼叫,則返回sqldatareader

sdr = cmd.executereader();

if (sdr.read())

else

c 鏈結資料庫

c 連線access程式 using system.data using system.data.oledb string strconnection provider microsoft.jet.oledb.4.0 strconnection data source c begaspnetnort...

C 鏈結ORACLE資料庫

using system using system.data using system.configuration using system.linq using system.web using system.web.security using system.web.ui using syste...

c 鏈結MySql資料庫

用mysql建立乙個表,然後輸出到控制台!首先電腦安裝完成mysql資料庫。1.net start mysql80 mysql80 為自己的資料庫名稱 接下來看到自己資料庫 服務已啟動成功 2.mysql u root p回車後 在enter password 輸入自己的mysql資料庫密碼,回車。...