> For the complete documentation index, see [llms.txt](https://johch3n611u.gitbook.io/c50108/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://johch3n611u.gitbook.io/c50108/ju-li-cheng-bei/201902/2019-0225-ss.md).

# 2019/0225/SS合併查詢\&ASP.NET驗證器

正規化後資料分散，查詢變得麻煩，&#x20;

所以使用合併查詢便以查詢 有關聯沒關聯 (主鍵有沒有放在對方表內當索引鍵)

灰色為運算值 藍色為功能

select 為查詢要顯示什麼欄位

\--完整表達法 班級.學號=學生.學生

如果兩個不相同表單具有相同欄位名稱，

關聯後要顯示就必須使用完整表達法，否則會模糊

## --合併查詢&#x20;

### --inner join 內部合併查詢

#### &#x20;(資料必須兩邊都要有)

```
--完整表達法 班級.學號=學生.學生
--合併查詢
--inner join 內部合併查詢

select 班級.*,員工.*,學生.*
--或以下
select 班級.教授編號,員工.姓名,班級.學號,學生.姓名,學生.性別, 
班級.課程編號,課程.名稱,課程.學分,班級.上課時間,班級.教室
from 班級 
inner join 學生 on 班級.學號=學生.學號 
inner join 課程 on 班級.課程編號=課程.課程編號
inner join 教授 on 班級.教授編號=教授.教授編號
inner join 員工 on 教授.身份證字號=員工.身份證字號
order by 學生.學號
```

要取一個與現在表單A無關聯之表單C欄位

就必須先相關聯另一個與這兩個欄位相關連之表單B

如果沒有條件運算式則顯示就會顯示資料全部完整筆數

聚合函數 用在統計 / 報表 ( 要看什麼就丟甚麼進去 )

```
select 課程.課程編號,課程.名稱,count(*) as 被選課數 
from 班級 
inner join 課程 on 班級.課程編號=課程.課程編號
group by 課程.課程編號,課程.名稱
```

其實有三種寫法，且寫完結果都一樣

第二種join寫法 用包含的方式

```
select  班級.教授編號,員工.姓名,教授.科系,教授.職稱,班級.學號,學生.姓名,學生.性別, 
班級.課程編號,課程.名稱,課程.學分,班級.上課時間,班級.教室
from 員工 inner join (教授 inner join 
(課程 inner join 
(班級 inner join 學生 on 班級.學號=學生.學號) 
on 班級.課程編號=課程.課程編號)  
on 班級.教授編號=教授.教授編號)
on 教授.身份證字號=員工.身份證字號
order by 學生.學號
```

第三種寫法 natural join 自然合併&#x20;

會產生卡式基關聯

{% embed url="<https://zh.wikipedia.org/wiki/%E7%AC%9B%E5%8D%A1%E5%84%BF%E7%A7%AF>" %}

解決方法為使用條件運算子去塞選 多重時則用邏輯運算子 去做條件相加&#x20;

```
select  班級.教授編號,員工.姓名,教授.科系,教授.職稱,班級.學號,學生.姓名,學生.性別, 
班級.課程編號,課程.名稱,課程.學分,班級.上課時間,班級.教室
from 班級, 學生, 課程, 教授, 員工
where  班級.學號=學生.學號 and 班級.課程編號=課程.課程編號 and 班級.教授編號=教授.教授編號
and 教授.身份證字號=員工.身份證字號
order by 學生.學號
```

### --outer join 外部合併查詢&#x20;

#### (ex.員工4位跟教授7位筆數不同，執行內部合併只能查到是教授也是員工的，但outer join則又分為left right 以左或右為主 ，主要的表所有筆數都會出現，而另一表沒有的值)&#x20;

```
--外部合併查詢 outer join

select *
from 員工 inner join 教授
on 員工.身份證字號=教授.身份證字號

select *
from 員工 left outer join 教授
on 員工.身份證字號=教授.身份證字號

select *
from 教授 left outer join 員工
on 員工.身份證字號=教授.身份證字號

select *
from 員工 right outer join 教授
on 員工.身份證字號=教授.身份證字號

select *
from 班級 right outer join 學生
on 班級.學號=學生.學號
where 班級.學號=null


select *
from 學生
where 生日 is null
```

![](/files/-LZXjTUZWkN9PsaIPem_)

又分為&#x20;

空值 =NULL&#x20;

空字串 'null'&#x20;

空 is null

NULL是 : "什麼也不是" 的意思 空字串是 : "什麼也沒有" 的意思

舉例來說, 硬碟在格式化之前, 它"什麼也不是" 格式化後, 不放東西, 這叫做"空的硬碟".

{% embed url="<http://www.programmer-club.com.tw/ShowSameTitleN/access/1416.html>" %}

### <https://www.itread01.com/articles/1478491504.html>

###

### --full join 全外部合併&#x20;

#### 左與右都放進來 哪邊沒有就哪邊用null表示

```
--full join
select *
from 班級 full outer join 學生
on 班級.學號=學生.學號
```

### --cross join 交叉合併&#x20;

#### 卡式基運算

```
--cross join
select *
from 班級 cross join 學生

select *
from 班級,學生
```

## ASP.NET驗證器 CustomValidatorl

### \<aspx>

```
<html>
<td>身分證字號：</td>
<td>




<asp:TextBox ID="txtID" 
runat="server" placeholder="A123456789" MaxLength="10"></asp:TextBox>


<asp:RequiredFieldValidator ID="RequiredFieldValidator3" 
Display="Dynamic" ControlToValidate="txtID" runat="server" 
ErrorMessage="(必填)" ForeColor="Red" Font-Size="10pt"></asp:RequiredFieldValidator>


<asp:RegularExpressionValidator ID="RegularExpressionValidator2" 
Display="Dynamic" ControlToValidate="txtID" 
ValidationExpression="[A-Za-z](1|2)\d{8}" runat="server" 
ErrorMessage="(格式有誤)" ForeColor="Red" 
Font-Size="10pt"></asp:RegularExpressionValidator>


<asp:CustomValidator ID="CustomValidator1" 
runat="server" ErrorMessage="(不合法)" ForeColor="Red"
Font-Size="10pt" OnServerValidate="CustomValidator1_ServerValidate" 
ControlToValidate="txtID"></asp:CustomValidator>




</td>
</html>

```

![](/files/-LZYDj7_aKTWJbDobxMz)

### \<aspx.cs> CustomValidator

foreach 字串陣列

substring ( 起始值 , 抓多少數量 )一碼一碼抓 ( 1 , 1) 第二碼抓一個 (3,2) 第四碼開始 一次抓2個

{% embed url="<http://xken831.pixnet.net/blog/post/435424412-%5Bjava%5D%E5%88%97%E5%87%BA%E5%AD%97%E4%B8%B2%E6%AF%8F%E5%80%8B%E5%AD%97%E5%85%83%E8%88%87substring%E7%9A%84%E7%94%A8%E6%B3%95>" %}

&#x20;*toupper* 將小寫字母轉換為大寫

Convert 萬用轉型態 Convert.ToInt16

```
   protected void CustomValidator1_ServerValidate(object source, ServerValidateEventArgs args)
        {
            string id = txtID.Text;

            string[] eng = {"A", "B", "C", "D", "E", "F", "G", "H", "J", "K",
                "L", "M", "N", "P", "Q", "R", "S", "T", "U", "V", "X", "Y", "W",
                "Z", "I", "O" };

            int intEng = 0;

            for(int i=0;i<eng.Length;i++)
            {
                if(eng[i]==id.Substring(0,1).ToUpper())
                {
                    intEng = i + 10;
                    break;
                }

            }

            //假設n=17
            int n1 = intEng / 10;  //n1=1
            int n2 = intEng % 10;  //n2=7



            int[] a = new int[9];
            for (int i = 0; i < a.Length; i++)
            {
                a[i] = Convert.ToInt16(id.Substring(i + 1, 1));

            }

            int sum = 0;
            for (int i = 0; i < 8; i++)
            {

                sum += a[i] * (8 - i);
            }

            int n = 0;
            n=n1 + n2 * 9 + sum + a[8];

            //n1 +n2*9+a[0]*8+a[1]*7*a[2]*6+a[3]*5

            
            if (n % 10 == 0)
                args.IsValid = true;
            else
                args.IsValid = false;
        }
```

```
n1 + n2 * 9 +a[0] * 8 + a[1] * + * a[2] *6 + .....
```

因為custombalidatorl 是在後端做運算 必須將資料往後端送

OnServerValidate="CustomValidator1\_ServerValidate"

所以其實已經接收了資料

所以應該要再多寫一個判斷不要擷取錯誤不合法表單資料入資料庫

#### asp控制項會自動幫妳寫好js一些不用在後端運算的直接擋在前端

### 那如何在後端擋表單&#x20;

```
<前端>
<asp:Button ID="Button1" runat="server" Text="確定送出" OnClick="Button1_Click" />
<input id="Reset1" type="reset" value="重設" />
</前端>
  
  
  
<後端>
protected void Button1_Click(object sender, EventArgs e)
        { if (this.IsValid)
           {
                Response.Write("表單已成功送到伺服器");
                //上面那行先假裝表示往資料庫存入的程式碼
            }
        }
</後端>
```

###

###

###

###

###

### ValidationSummary 控制器統合控制項&#x20;

#### ( 驗證器錯誤訊息排版工具 )

Text = 永遠顯示

errormessege = 錯誤才會顯示

display ="None" 不顯示在驗證器存在的那個欄位 顯在在控制器統合控制項上

```
 <asp:ValidationSummary ID="ValidationSummary1" 
 runat="server" Font-Size="10" ForeColor="Red"
  DisplayMode="BulletList" ShowMessageBox="true" />
```

```
 /// <summary>
        /// ValidationSummary1 控制項。
        /// </summary>
        /// <remarks>
        /// 自動產生的欄位。
        /// 若要修改，請將欄位宣告從設計工具檔案移到程式碼後置檔案。
        /// </remarks>
        protected global::System.Web.UI.WebControls.ValidationSummary ValidationSummary1;
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://johch3n611u.gitbook.io/c50108/ju-li-cheng-bei/201902/2019-0225-ss.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
