通过c#中的文本框值从数据库中选择 [英] select from database by textbox value in c#
本文介绍了通过c#中的文本框值从数据库中选择的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好
如果文本框值已更改,我如何通过新文本框值而不是旧值从数据库中进行选择?
使用c#和MySql
我的代码
hello
If a textbox value has changed, how can I select from a database by the new textbox value , not the old value?
using c# and MySql
my code
string constring = "datasource=127.0.0.1;username=root;password=admin";
string Query = "select * from mohamed.usercompany1 where office = '" + textBox1.Text + "' ;";
MySqlConnection conDataBase = new MySqlConnection(constring);
MySqlCommand cmdDataBase = new MySqlCommand(Query, conDataBase);
DataSet DataSet1 = new DataSet();
MySqlDataReader myReader;
try
{
conDataBase.Open();
myReader = cmdDataBase.ExecuteReader();
if (myReader.Read())
{
string scode = myReader.GetInt32("techname").ToString();
textBox1.Text = (string)myReader["techname"];
comboBox2.Items.Add(scode).ToString();
listView1.Items.Add(scode).ToString();
this.Refresh();
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
推荐答案
TextBox有TextChanged事件,当TextChanged触发器再次调用该方法时。
Hi TextBox has TextChanged event,when the TextChanged trigger,can invoke again the method.
文本更改事件中的
逻辑
这篇关于通过c#中的文本框值从数据库中选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文