如何根据选择的组合框从数据库填充文本框值。

问题描述:

在我的物品主要跟随栏中存在。



否,类型,描述,部件号



如果用户选择零件号(组合框),则在我的发票表单上,类型和说明(文本框)应根据零件号(组合框)值的选择进行填充。





任何人都可以给我建议



提前致谢。

In my Item Master following column are exists.

No, Type , Desc , Part No.

On My Invoice form if user select Part no (combo box) , Type & Desc (Text box) should get fill as per selection of Part no (combo box) value.


Can any one give me suggestion

Thanks in advance.

在你的组合框上添加onselectedindexchanged事件。

然后在代码后面,即在.vb文件中







string partno = yourcomboboxname.SelectedItem.Value;



然后使用此partno从db获取整行。



然后将这些值添加到您需要的文本框中。



如果partno将是unquie然后你得到单数据库中的一行。





例如



SqlDataReader reader = cmd。 ExecuteReader(从表名中选择partno =+ partno;



while(reader.Read)

{

TextBox1.Text =读者[CoulmnName];

}



在vb中使用相同的代码没有;:)



希望这能解决你的问题......
Add event onselectedindexchanged on your combobox.
then in code behind i.e in .vb file

write

string partno = yourcomboboxname.SelectedItem.Value;

then use this partno to fetch whole row from db.

then add those value to your required text box.

if partno will be unquie then you get single row from database.


e.g.

SqlDataReader reader = cmd.ExecuteReader("Select from tablename where partno = " +partno;

while(reader.Read)
{
TextBox1.Text = reader["CoulmnName"];
}

Use same code in vb WITHOUT ";" :)

Hope this will solve your problem.....