您好我有以下代码,我需要在我的应用程序中设置文本框的 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);
}
}