簡體   English   中英

我的 SQL 服務器上有一個檢查約束,如何在 c# 中設置檢查約束的驗證?

[英]I have a check constraint on my SQL server, how do i set a validation for the Check Constraint in c#?

檢查約束的定義是

 (NOT [alt_code1] collate Latin1_General_BIN like '%[^-0-9A-Z_/&$!]%')

我如何在 c# 中進行驗證? 另外,collat​​e Latin1_General_BIN 是否區分大小寫?

private void txtAlt_Code1_Validating(object sender, CancelEventArgs e)
{
    //code
}

您可以嘗試使用Regular Expression

var regex = @"^[-0-9A-Z_/&]$!";
var match = Regex.Match(input, regex);

if (!match.Success)
{
    // raise error
}

嗨,我發現此代碼有效

Regex regex = new Regex(@"[^-0-9A-Z_/&$!]");
                Match match = regex.Match(input);
                if (match.Success)
                {
                    // raise error
                }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM