[英]ADO.NET how to use parameter in dataset?
Where i need initialize parameter, for when form will open, to make it work? 我需要初始化参数的地方,何时打开表单,使其工作?
Query: 查询:
SELECT id, id_work, name FROM ttz WHERE (id_work = @idwork)
I want @idwork value = textBox1.Text 我想要@idwork值= textBox1.Text
I did this : 我是这样做的:
private void frmTTZ_Load(object sender, EventArgs e)
{
this.ttzTableAdapter.Fill(this.dbDataSet.ttz,Convert.ToInt32(textBox1.Text));
}
Are you using a typed DataSet which autogenerates the update statements? 您是否在使用自动生成更新语句的类型化数据集? Your image suggests this since it contains the TableAdapters.
您的图像建议这样做,因为它包含TableAdapters。
Yes.
是。 When i open form, i want do query with my parameter.
当我打开表格时,我想用我的参数查询。
Then all is already there. 然后一切都已经在那里。 You only have to create an instance of
ttzTableAdapter
and call the GetData
or the Fill
method. 您只需要创建
ttzTableAdapter
的实例并调用GetData
或Fill
方法。
var da = new ttzTableAdapter();
ttz tbl = da.GetData(textBox1.Text);
or by passing a ttz-table: 或通过传递ttz表:
var tbl = new ttz();
da.Fill(tbl, textBox1.Text);
If "ttz" is a TableAdapter then 如果“ ttz”是TableAdapter,则
var result = ttzTableAdapter.GetData(textBox1.Text); var result = ttzTableAdapter.GetData(textBox1.Text);
Hope this helps 希望这可以帮助
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.