简体   繁体   中英

ADO.NET how to use parameter in dataset?

dbDataSet

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

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.

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.

var da = new ttzTableAdapter();
ttz tbl = da.GetData(textBox1.Text);

or by passing a ttz-table:

var tbl = new ttz();
da.Fill(tbl, textBox1.Text);

MSDN: TableAdapters - Overview

If "ttz" is a TableAdapter then

var result = ttzTableAdapter.GetData(textBox1.Text);

Hope this helps

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM