在VB.NET中更新数据集中的值 [英] Update value in DataSet in VB.NET
问题描述
您好,所有专家,
我已经声明了一个数据集(ds).该数据集将从我的数据库中获取值,并且在数据集中具有1个称为"Magin"的列.
在我的表单中,我创建了1个名为"Magin"的文本框.
当我在Magin文本框中输入4时,我希望数据集中的所有边距值都将更新为4(基于边距文本框值).
我是否可以根据文本框中的值更新数据集中的值?
注意:
我的数据集最多可以存储100行.请避免使用循环
谢谢
TONY
Hi all experts,
i have declared one dataset (ds). this dataset will get values from my database and in dataset has 1 col called "Magin".
In my form, i created 1 text box called "Magin".
when i input 4 in Magin Text box, i want all magin value in dataset will update to 4 (based on magin text box value).
Is it possible that i can update values in dataset based on the value on my text box?
Note:
My dataset can store from 100 rows up.please avoid to use loop
Thanks
TONY
推荐答案
托尼,
即使听起来像是一项家庭作业,也可以尝试一下.使用列的Expression属性将其更新为所需的值.
Hi Tony,
even if it sounds like a homework, try this. Use Expression property of a column to update it to a desired value.
private void button1_Click(object sender, EventArgs e)
{
// create a new ds with a table and a column
DataSet ds = new DataSet();
ds.Tables.Add("Table1");
ds.Tables[0].Columns.Add("Magin", typeof(int));
// populate some test data
for (int i = 0; i < 100; i++)
{
DataRow dr = ds.Tables[0].NewRow();
dr[0] = i;
ds.Tables[0].Rows.Add(dr);
}
// update the column to a value
ds.Tables[0].Columns["Magin"].Expression = "4";
}
请记住,字符串值应加引号.
欢呼
Keep in mind that string values should be quoted.
Cheers
For I As Integer = 0 To DatasetName.Tables("TableName").Rows.Count - 1
DatasetName.Tables("TableName").Rows(I).Item(0) = TextBox1.Text
Next
这篇关于在VB.NET中更新数据集中的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!