0
以下代碼導致System.Data.SqlClient.SqlException: Timeout expired
。Sql超時錯誤,但爲什麼?
const string sqlStmt = @"SELECT *
FROM CUSTOMER_INFO
WHERE CUSTOMER_NO = @CUSTOMER_NO;";
SqlCommand command = new SqlCommand(sqlStmt, connection);
command.Parameters.AddWithValue("@CUSTOMER_NO", txtAccountNo.Text.Trim().ToUpper());
但這並不超時......
const string sqlStmt = @"SELECT *
FROM CUSTOMER_INFO
WHERE CUSTOMER_NO = @CUSTOMER_NO;";
SqlCommand command = new SqlCommand(sqlStmt, connection);
command.Parameters.Add("@CUSTOMER_NO", SqlDbType.VarChar, 25).Value = txtAccountNo.Text.Trim().ToUpper();
我不明白爲什麼,任何人都可以告訴我嗎?
你在第二個查詢中得到了期望的結果嗎? –
看看這篇文章,這可能會幫助你:http://stackoverflow.com/questions/345323/addwithvalue-without-dbtype-causing-queries-to-run-slowly – christiandev
@Prasanth - 是的,我做了,但我在學習c#,只是想明白爲什麼第一個不起作用? – Stuart