SqlDataReader区分大小写

时间:2013-09-08 20:19:15

标签: c# winforms sql-server-2008-r2 case-sensitive

using (SqlConnection myDatabaseConnection = new SqlConnection(myConnectionString.ConnectionString))
{
    myDatabaseConnection.Open();

    using (SqlCommand mySqlCommand1 = new SqlCommand("Select * from Emp where Fname = @Fname", myDatabaseConnection))
    {
        mySqlCommand1.Parameters.AddWithValue("@FName", NametextBox.Text);
        SqlDataReader DR1 = mySqlCommand1.ExecuteReader();
        if (DR1.Read())
        {
            MessagabeBox.Show("TEST");
        }
    }
}

例如,我在数据库中有一个Fname Smith,然后在NametextBox中键入Smith,messageBox将显示。但是当我输入smithSMITH时,它仍会读取。我该怎么做才能使读者区分大小写?

1 个答案:

答案 0 :(得分:1)

尝试更改排序规则,例如

Select * from Emp where Fname COLLATE Latin1_General_CS_AS = @Fname