您好我有以下代碼,我需要在我的應用程序中設置文本框的MaxLength。代碼似乎確定,但它不工作。任何人都可以看到有什麼問題。使用開關語句來設置文本框大小
private void cbType_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
string constring = "Data Source=.;Initial Catalog=db.MDF;Integrated Security=True";
string Query = "select * from RePriorities where Priority='" + cbType.SelectedItem.ToString() + "' ;";
SqlConnection conDataBase = new SqlConnection(constring);
SqlCommand cmdDataBase = new SqlCommand(Query, conDataBase);
SqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
string sType = myReader.ToString();
switch (sType)
{
case "Low": txtDesc.MaxLength = 5; break;
case "Medium": txtDesc.MaxLength = 10; break;
case "High": txtDesc.MaxLength = 1; break;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
描述「但它不工作」。不清楚。 –
輸出sxt到txtDesc中,可能會幫助 – athabaska
調試代碼。在交換機上,sType的值是多少? – stevepkr84