TextBox文本更改无法正常工作 [英] TextBox Text Change not working

查看:88
本文介绍了TextBox文本更改无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表单,您可以在其中输入文本框中的名称,并填充下一个文本框。由于某些原因它无法正常工作。我究竟做错了什么?这是我的代码:



I have a form to where you can enter a name in a textbox and it populates the next textbox. FOr some reason it is not working. What am I doing wrong? Here is my code:

 protected void TextBoxLongName_TextChanged(object sender, EventArgs e)
        {
            SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con2.Open();

            SqlCommand scmd2 = new SqlCommand("Select INST_ID, LongName from Table23 where LongName = '" + TextBoxINST_ID.Text + "'", con2);
            SqlDataReader dr2 = scmd2.ExecuteReader();

            if (dr2.Read())

            {
                TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
            }
            dr2.Close();
            con2.Close();
        }
    }
}

推荐答案

您的代码几乎正确。

您已给出完全匹配条件。可能是用户输入错误



在这里看到一个错误的输入,你在使用TextBoxLongName文本框进行输入和搜索,这个TextBoxINST_ID用于填充结果。希望所以这是错误的,所以你改变了这一点。

protected void TextBoxLongName_TextChanged(object sender, EventArgs e)
        {
            SqlConnection con2 = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["HotConnectionString"].ConnectionString);
            con2.Open();
 
            SqlCommand scmd2 = new SqlCommand("Select INST_ID, LongName from Table23 where LongName = '" + TextBoxLongName.Text + "'", con2);
            SqlDataReader dr2 = scmd2.ExecuteReader();
 
            if (dr2.Read())
 
            {
                TextBoxINST_ID.Text = dr2["INST_ID"].ToString();
            }
            dr2.Close();
            con2.Close();
        }
    }
}


这篇关于TextBox文本更改无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆