在内存中向数据表添加行 [英] Adding Row to Datatable in Memory
问题描述
我的要求是我想在内存中创建数据表并添加列并添加行。并在其上插入数据。要插入数据我将使用TextBox.As MSDN我知道如何在SourceCode中输入它但我需要通过TextBox输入数据。
以下代码我写了...但它不是我的要求..如前所述我希望按文本框输入数据。
Dim Mytable作为新数据表
Dim Col_one作为新数据列
Mytable.Columns.add(Col_one)
Dim Row1 as datarow = Mytable.NewRow
Row1(Col_one)=" String value"
Mytable.Row.add(Row1)
Datagridview1.datasource = Myytable
您的代码就像
Row1(Col_one)= MyTextbox.Text
或者如果它是数字/日期值,则需要转换为特定类型(int32值的示例)
Row1(Col_one)= Convert.ToInt32 (MyTextbox.Text)
Hi ,
My Requirement is i want to Create a Datatable in memory and add Columns and add Rows .And Inserting data on it . To Insert data I am Going to Use TextBox.As MSDN I Knew how to Enter it in SourceCode but I need to Enter Data By TextBox.
Following Code i wrote...But it is not My Requirement ..as Earlier Mentioned i want to Enter Data by Text Box.
Dim Mytable as new datatable
Dim Col_one as new dataColumn
Mytable.Columns.add(Col_one)
Dim Row1 as datarow=Mytable.NewRow
Row1(Col_one)= "String value"
Mytable.Row.add(Row1)
Datagridview1.datasource=Myytable
Your code would be like
Row1(Col_one)= MyTextbox.Text
Or in a case if it is numeric/date value, you would need to cast to specific type (example for int32 values)
Row1(Col_one)= Convert.ToInt32(MyTextbox.Text)
这篇关于在内存中向数据表添加行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!