SQL SERVER-筆記3
1、複習
->select查詢詳解***********
select distinct\top ... --(5)投影
from -- (1)找到表
where -- (2)過濾掉我們不需要的資料
group by --(3)分組操作
having --(4)對分組後的資料進行過濾。
order by --(6)排序操作
->union:去重 union all:不去重
->datediff(month,startdate,enddate)**********
->join:內連線*******
2、Ado.Net 連線資料庫
->類庫:一組 C#操作資料庫的類庫。
->連線字串:server=.;uid=sa;pwd=123456;database=demo
->連線字串配置檔案配置化
->Sql連線字串輔助型別:SqlConnStringBuilder
->SqlConnection型別
->ConnectionString:連結字串
->Open() 開啟連結
->Close()關閉連線(還可以繼續開啟)
->Dispose() 把管道關閉
->連線池技術
->啟用和禁用連線池
->設定連線池的大小
->內連線物件
3、SqlCommond型別
->CmdText:Sql命令
->CmdType:Sql型別
->關聯SqlConnection
->執行Sql語句
->ExcuteNoneQuery()
->ExcuteScalar()
4、使用者操作案例
->編寫一個使用者註冊的案例
->編寫一個使用者登入案例
5、SQL注入
->登陸窗體破解
->配置檔案
->首先在 app.Config檔案中新增 節點,如下:
<connectionStrings>
<add name="sql2" connectionString="server=.;uid=sa;pwd=123456;database=demo"/>
</connectionStrings>
->在專案中新增System.Configuration程式集引用(控制檯和WinFrm才需要)
->在專案中使用ConfigurationManager獲取連結字串。
例如:ConfigurationManager.ConnectionStrings["配置的節點的Name名字"].ConnectionString
->ExcuteScalar()
->所有資料進行引數化
6、案例:資料庫資料匯出和匯入
思路:
--思路:
1、找到檔案
2、讀取檔案
3、第一行 忽略
4、insert
7、SqlCommond ExcuteReader
8、作業:
->省市選擇Demo
->把省市的資料匯出到一個文字檔案。
User ID=s