public
string
getconnectionstring
(string sqlname,
string basename,
string userid,
string password)
;initial catalog =;user id =;pwd ="
, sqlname, basename, userid, password);}
public
string
getconnectionstring
(string sqlname,
string basename,
bool security)
; initial catalog =; integrated security ="
, sqlname, basename, security);}
public
string
getconnectionstring
(string serverip,
int serverport,
string userid,
string password,
string basename)
;port=;user=;password=;database="
,serverip ,serverport,userid,password,basename)
;}
private
void
button2_click
(object sender,
eventargs e)
else
}catch
(exception
)}
主要使用的是sqlcommand類庫,建立sqlcommand物件時可以通過建構函式直接繫結命令語句和sqlconnection,然後在按實際情況執行以下三個方法:
方法使用情況
executenonquery
執行無返回內容的sql命令,create、insert、update、delete等
executescalar
執行返回第一行第一列的資料,其實也就是返回乙個值的命令,型別為object
endexecutereader
執行返回多行資料,select居多,返回型別是sqldatareader
executenonquery 用例;
private
void
button2_click
(object sender,
eventargs e)
catch
(exception
)}
executescalar 用例
try
catch
(exception
)
endexecutereader 用例
string str =
"data source=desktop-ckgfuub;initial catalog=client;user id = sa;pwd = herry084462"
;sqlconnection conn =
newsqlconnection
(str)
; conn.
open()
;//string command = "insert into final values ('bi','女',24)";
string command =
"select * from final"
;sqlcommand sqlc =
newsqlcommand
(command, conn)
;sqldatareader reader = sqlc.
executereader()
;if(!reader.hasrows)
task.
run(()
=>}}
catch
(exception)}
);
查詢資料庫的所有表名
// 查詢資料庫的所有表名
use mysoftware
select name from sysobjects where type=
'u'
create table student (
idint
identity(1
,1) primary key not null
,stuname nvarchar(10
),stu*** char(2
)null
,stuage int
null
)
identity(1,1)自遞增
insert into tablename values
(value1,value1,value1,value1)
update addressbook
set name=
'1'where name=
'2'
delete from
addressbook
where id=
10
c sqlserver資料庫連線字串
sql連線字串 data source myserveraddress initial catalog mydatabase user id myusername password mypassword user id與password可以簡寫為uid與psd data source myserve...
git與github連線使用
上面命令表示,將當前分支推送到origin主機的對應分支。如果當前分支只有乙個追蹤分支,那麼主機名都可以省略。git push 如果當前分支與多個主機存在追蹤關係,那麼這個時候 u選項會指定乙個預設主機,這樣後面就可以不加任何引數使用git push。git push u origin master...
左連線與右連線,外連線與內連線
左 left join select form tab1 left join tab2 on user id tab2.user id where tab1.user id 4 意思 就是讓tab1裡的user id為4的所有friend id當作tab2裡的user id,在tab2裡查詢符合的資...