使用c#的windows应用程序 [英] windows application using c#

查看:65
本文介绍了使用c#的windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当在textbox1中输入id时,如何在textbox2中自动显示相应的名称?????





其中表名:员工详细信息

栏:员工ID,员工姓名



我的窗体表格如下









员工ID:textBox1 textBox2





当我在textBox1中键入Employee ID时,它应该自动在textBox2中显示类型为textBox1中ID的相应名称。

how to display automatically respective name in textbox2 when id is typed in the textbox1?????


where table name : Employee Details
columns : EmployeeID, EmployeeNAME

my windows form looks as follows




Employee ID : textBox1 textBox2


when i type Employee ID in textBox1, it should automatically display the respective name in textBox2 for the ID in typed textBox1.

推荐答案

嗨。我想你使用LINQ。

Hi. i suppose you use LINQ.
private void TextBox1_TextChanged(object sender, TextChangedEventArgs e)
       {
           int id = Convert.ToInt32(TextBox1.Text);
           TextBox2.Text=//you must write :select Name from myTable where myTable.ID==id;
       }



你的问题并不明显。

你必须确定你的来源。 SQL表或List< string> ?


your question isn''t obvious.
you must determine your source. SQL table or List<string> ?


你的问题不明确,但我认为你是从特定的Id中获取数据库中的数据。你可以在textChanged事件的文本框中这样做。







Your question is not clear but i supposed you are fetching data from Database against a specific Id. you can do this in textChanged Event of the text box.



 // here someFunctionWhichWillreturnNameAgainstId is a function which takes id as parameter and return the name.
private void textBoxId_TextChanged(object sender, EventArgs e)
        {
            string id = textBoxId.Text;
            textName.Text =  someFunctionWhichWillreturnNameAgainstId(id);
        }

    private string someFunctionWhichWillreturnNameAgainstId(string id) {
            string cm = "select EmployeeNAME from Employee Details where  EmployeeID=" + id;
            string constr = "you connection stirng";
            SqlConnection con = new SqlConnection(constr);
            SqlCommand sqlcmd = new SqlCommand(cm,con);
            object name   =  sqlcmd.ExecuteScalar();
            con.Close();
            return name.ToString();

            
        }


嗨朋友...


$ b这个EmployeeID的$ b应该不重复(数据库中的主键)

然后textbox1控件的文本变换事件你必须正确代码...



hi friend...

for this EmployeeID should be not duplicate(primary key in database)
and then the event of text chenge for textbox1 control you have to right the code...

private void textBoxId_TextChanged(object sender, EventArgs e)
        {
      string empname="select EmployeeName from Employee_Details where   EmployeeID='"+textbox.text+"' ";
con.open()
MySqlCommand cmd = new MySqlCommand(empname, con);
MySqlDataReader dr = cmd.ExecuteReader();
if(dr.read)
{
textbox2.text=dr["EmployeeName"].tostring;
}
con.close();
        }





也使用SQL Server的命名空间和连接字符串(如果使用此数据库)

它实际上是你想要的......

谢谢



also use Namespace and connection String for SQL Server(if you using this database)
it is achiving that actually you want...
thanks


这篇关于使用c#的windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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