
DataBase控件中有2個屬性:Type(選擇所連接配接資料庫的類型,Ventuz4提供5個)
ConnectionString:(資料庫連接配接字元串)
Query:執行查詢sql語句,傳回需要的資訊與對應的資料。
NonQuery:執行更新sql語句。新增删除修改,傳回ture與false.
Scalar:執行統計sql語句,傳回結果的第一行第一列。
ColCocat:文檔上介紹說接收傳回數組,然後通過replase進行分割擷取想要的值
Row:和Query組合使用,可以擷取更為精準的值
第一種:DataBase輸入資料庫連接配接位址:Data Source=localhost;Initial Catalog=Test;integrated Security=true
Query輸入查詢語句:select name from skt
Row:需要添加對應的傳回值接收
第二種:DataBase輸入資料庫連接配接位址:Data Source=localhost;Initial Catalog=Test;integrated Security=true
Scallar:輸入查詢語句:select count(*) from skt
第三種:直接上代碼了
string str = "Data Source=localhost;Initial Catalog=Test;integrated Security=true";
using (SqlConnection con = new SqlConnection(str))
{
con.Open();
string sqlstr = "select count(*) from skt";
SqlCommand cmd = new SqlCommand(sqlstr,con);
num = cmd.ExecuteScalar().ToString();
}