有两个winform要求:在winform1查询数据库将查询的结果传到winform2里让它在textbox中显示查询出的结果!

例如winform1有textbox1用户输入学号查询!单击"提交"调用winform2然后在winform2中的textbox1中显示结果!假如用户输入1然后在winform2中的textbox中显示他的姓名!

在winform1中:
winform2 w2=new winform2()
w2.textbox.text=name

这个name是数据库查询出来的name..
温馨提示:答案为网友推荐,仅供参考
第1个回答  2010-11-10
这个不难,你要源代码吗?你是什么数据库?
Form1中:
先定义一个public
public String ID;
public String Name;
private void Form1_Load(object sender, EventArgs e)
{ ID =this.textBox1.Text;
链接字符串。。
Name=select name from 表 where id=ID。。
}
private void button1_Click(object sender, EventArgs e)
{
Form2 dlg = new Form2();
dlg.name2 = this.Name.ToString();
dlg.Show();
}
}
Form2中:
public string name2;
private void Form2_Load(object sender, EventArgs e)
{ this.textBox2.Text = this.name2;
}
第2个回答  2010-11-09
这个简单,就是一个传值、接收、查询和赋值的过程。

第一步是传值:
在按钮的点击事件中这样写
string art = textbox1.text;
winform2 mef = new winform2(art);
mef.ShowDialog();
传值完成。

第二步接收:
在 public partial class winform2 : Form的{}中这样写:

string art2;
public materialEdit(string art1)
{
art2 = art1;
InitializeComponent();
}
完成接收。
这个是个基本的思路,接收的值可以是ID,也可以是人名。如果是ID那么在form2中进行一个SQL查询就可以查询到数据库中的人名,然后赋值为form2中的textbox.text. 赋值在窗体加载下写。 如果form1的textbox1中写的是ID,form2中的textbox同意显示ID,那么查询都省了,接收后就直接textbox.text=art2.

全部手写,没有半点是网上查询。
第3个回答  2010-11-08
在winform1中:
winform2 w2=new winform2()
w2.textbox.text=name
相似回答
大家正在搜