问:向数据集添加列 [英] Q: Adding a column to a dataset

查看:80
本文介绍了问:向数据集添加列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




有人可以帮我解决以下问题,希望简单吗?


我有一张桌子,我有连接到数据集。我希望在表格的开头添加一个新栏目



并用增量值填充它,例如如果表格看起来像这样:
这样:


23 56

45 87

21 67 < br $>
34 09

我希望将其更改为:


1 23 56
2 45 87

3 21 67

4 34 09


其实我在做什么试图做的是在

第一列中为表格提供一个索引键。


有人可以帮忙吗?


提前致谢


Geoff

Hi

Can anybody help me with the following, hopefully simple, question?

I have a table which I''ve connected to a dataset. I wish to add a new column
to the beginning of the table
and to fill it with incremental values e.g. if the tables looks
like this:

23 56
45 87
21 67
34 09

I''d like it to be changed into:

1 23 56
2 45 87
3 21 67
4 34 09

In fact, what I''m trying to do is to give the table an index key in the
first column.

Can anybody help?

Thanks in advance

Geoff

推荐答案

这将在创建两个初始列后添加新列。新栏目

不会在序号为0,但是,如果你使用的是命名列,因为我们这里是b $ b那么它真的不重要。

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As

System.EventArgs)处理Button1.Click

Dim t As New DataTable(" MyTable")

Dim c1 As New DataColumn(& ;姓名)

Dim c2 As New DataColumn(地址)


t.Columns.Add(c1)

t.Columns.Add(c2)


''添加一些数据

Dim r As DataRow = t.NewRow()

r(" Name")=" Terry"

r(" Address")=" The World"

t.Rows.Add(r)


''添加更多

r = t.NewRow()

r(" Name")=" Crystal Gayle" ;

r(地址)=世界

t.Rows.Add(r)


For每个r in t.Rows

Debug.WriteLine(r(" Name")+" - + r(地址))

下一页


''添加新的PK栏

t.Columns.Add (ID)

Dim i As Int32 = 0

For each r in t.Rows

r(" ID")= (i).ToString

Debug.WriteLine(r(" ID")+" - " + r(" Name")+" - " +

r(地址))

i + = 1

下一页


-


OHM(特里伯恩斯)

。 。 。单手人。 。

" Geoff Jones" < GE *** @ NODAMNSPAM.com>在消息中写道

news:40 ********************** @ news.dial.pipex.com。 ..
This will add a new column after creating two initial columns.The new column
will not be at ordinal 0, however, if you are using named columns as we are
here then it should not matter really.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As New DataTable("MyTable")
Dim c1 As New DataColumn("Name")
Dim c2 As New DataColumn("Address")

t.Columns.Add(c1)
t.Columns.Add(c2)

''Add Some Data
Dim r As DataRow = t.NewRow()
r("Name") = "Terry"
r("Address") = "The World"
t.Rows.Add(r)

''Add Some More
r = t.NewRow()
r("Name") = "Crystal Gayle"
r("Address") = "The World"
t.Rows.Add(r)

For Each r In t.Rows
Debug.WriteLine(r("Name") + " - " + r("Address"))
Next

''Add the new PK Column
t.Columns.Add("ID")
Dim i As Int32 = 0
For Each r In t.Rows
r("ID") = (i).ToString
Debug.WriteLine(r("ID") + " - " + r("Name") + " - " +
r("Address"))
i += 1
Next

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40**********************@news.dial.pipex.com. ..


任何人都可以帮我解决以下问题,希望简单,问题吗?

我有一张桌子,我已连接到数据集。我希望在表格的开头添加一个新的
列,并用增量值填充它,例如如果表格看起来像这样:

23 56
45 87
21 67
34 09

我是d喜欢把它改成:1/2
2 45 87
3 21 67
4 34 09

实际上,我要做的是在第一栏中给表格一个索引键。

有人可以帮忙吗?

提前致谢

Geoff
Hi

Can anybody help me with the following, hopefully simple, question?

I have a table which I''ve connected to a dataset. I wish to add a new column to the beginning of the table
and to fill it with incremental values e.g. if the tables looks
like this:

23 56
45 87
21 67
34 09

I''d like it to be changed into:

1 23 56
2 45 87
3 21 67
4 34 09

In fact, what I''m trying to do is to give the table an index key in the
first column.

Can anybody help?

Thanks in advance

Geoff



嗨Terry


非常感谢你的回复和代码。


有没有办法使用SQL命令,例如使用ALTER?


Geoff


" One Handed Man(OHM - Terry Burns)" < news.microsoft.com>在消息中写道

news:uz ************** @ TK2MSFTNGP09.phx.gbl ...
Hi Terry

Many thanks for the reply and the code.

Is there a way of doing this using an SQL command e.g. using ALTER?

Geoff

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message
news:uz**************@TK2MSFTNGP09.phx.gbl...
这将添加一个新的创建两个初始列后的列。新的
列不会在序号0,但是,如果你使用命名列,因为我们
在这里,那真的应该没关系。

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1.Click
Dim t As New DataTable(" MyTable")
Dim c1 As新的DataColumn(名称)
Dim c2 As New DataColumn(Address)

t.Columns.Add(c1)
t.Columns.Add(c2 )添加一些数据
Dim r As DataRow = t.NewRow()
r(" Name")=" Terry"
r( 地址)=世界
t.Rows.Add(r)

''添加更多
r = t.NewRow()
r(" ;姓名)=水晶盖尔
r(地址)=世界
在t.Rows
Debug.WriteLine(r(" Name")+" - + r(地址))
下一页

''添加新的PK栏
t.Columns.Add(" ID")
Dim i因为Int32 = 0
对于每个r in t.Rows
r(ID)=(i).ToString
Debug.WriteLine(r(" ID")+" - " + r(" Name")+" - " +
r(" Address"))
i + = 1
下一页
-

OHM(特里伯恩斯)
。 。 。单手人。 。

" Geoff Jones" < GE *** @ NODAMNSPAM.com>在消息中写道
新闻:40 ********************** @ news.dial.pipex.com。 ..
This will add a new column after creating two initial columns.The new column will not be at ordinal 0, however, if you are using named columns as we are here then it should not matter really.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As New DataTable("MyTable")
Dim c1 As New DataColumn("Name")
Dim c2 As New DataColumn("Address")

t.Columns.Add(c1)
t.Columns.Add(c2)

''Add Some Data
Dim r As DataRow = t.NewRow()
r("Name") = "Terry"
r("Address") = "The World"
t.Rows.Add(r)

''Add Some More
r = t.NewRow()
r("Name") = "Crystal Gayle"
r("Address") = "The World"
t.Rows.Add(r)

For Each r In t.Rows
Debug.WriteLine(r("Name") + " - " + r("Address"))
Next

''Add the new PK Column
t.Columns.Add("ID")
Dim i As Int32 = 0
For Each r In t.Rows
r("ID") = (i).ToString
Debug.WriteLine(r("ID") + " - " + r("Name") + " - " +
r("Address"))
i += 1
Next

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40**********************@news.dial.pipex.com. ..


任何人都可以帮我解决以下问题,希望简单,问题吗?

我有一张桌子,我已连接到数据集。我希望在表格的开头添加一个新的
Hi

Can anybody help me with the following, hopefully simple, question?

I have a table which I''ve connected to a dataset. I wish to add a new


,并用增量值填充它,例如:如果表格看起来像这样:

23 56
45 87
21 67
34 09

我是d喜欢把它改成:1/2
2 45 87
3 21 67
4 34 09

实际上,我要做的是在第一栏中给表格一个索引键。

有人可以帮忙吗?

提前致谢

Geoff
to the beginning of the table
and to fill it with incremental values e.g. if the tables looks
like this:

23 56
45 87
21 67
34 09

I''d like it to be changed into:

1 23 56
2 45 87
3 21 67
4 34 09

In fact, what I''m trying to do is to give the table an index key in the
first column.

Can anybody help?

Thanks in advance

Geoff




ALTER TABLE销售ADD ID整数;


-


OHM(特里伯恩斯)

。 。 。单手人。 。

" Geoff Jones" < GE *** @ NODAMNSPAM.com>在消息中写道

news:40 ********************** @ news.dial.pipex.com。 ..
ALTER TABLE Sales ADD ID Integer;

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40**********************@news.dial.pipex.com. ..
嗨Terry

非常感谢您的回复和代码。

有没有办法使用SQL命令执行此操作,例如:使用ALTER?

Geoff

单手男子(OHM - Terry Burns) < news.microsoft.com>写在
消息新闻:uz ************** @ TK2MSFTNGP09.phx.gbl ...
Hi Terry

Many thanks for the reply and the code.

Is there a way of doing this using an SQL command e.g. using ALTER?

Geoff

"One Handed Man ( OHM - Terry Burns )" <news.microsoft.com> wrote in message news:uz**************@TK2MSFTNGP09.phx.gbl...
这将在创建两个后添加一个新列初始列。新的
This will add a new column after creating two initial columns.The new


将不在序号0,但是,如果您使用命名列,因为我们
will not be at ordinal 0, however, if you are using named columns as we


这里真的应该没关系。

Private Sub Button1_Click(ByVal sender As System.Object,ByVal e As
System.EventArgs)处理Button1.Click
Dim c1 As New DataColumn(" Name")
Dim c2 As New DataColumn(" Address")

> t.Columns.Add(c1)
t.Columns.Add(c2)
''添加一些数据
Dim r As DataRow = t.NewRow()
r(" Name")=" Terry"
r(" Address")=" The World"
t.Rows.Add(r)
''添加更多
r = t.NewRow()
r(" Name")=" Crystal Gayle"
r(" Address")= The World
t.Rows.Add(r)
对于每个r in t.Rows
Debug.WriteLine(r(" Name")+" - + r(地址))
下一页

''添加新的PK栏
t.Columns.Add(" ID")
Dim i因为Int32 = 0
对于每个r in t.Rows
r(ID)=(i).ToString
Debug.WriteLine(r(" ID")+" - " + r(" Name")+" - " +
r(" Address"))
i + = 1
下一页
-

OHM(特里伯恩斯)
。 。 。单手人。 。

" Geoff Jones" < GE *** @ NODAMNSPAM.com>在消息中写道
新闻:40 ********************** @ news.dial.pipex.com。 ..
here then it should not matter really.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click
Dim t As New DataTable("MyTable")
Dim c1 As New DataColumn("Name")
Dim c2 As New DataColumn("Address")

t.Columns.Add(c1)
t.Columns.Add(c2)

''Add Some Data
Dim r As DataRow = t.NewRow()
r("Name") = "Terry"
r("Address") = "The World"
t.Rows.Add(r)

''Add Some More
r = t.NewRow()
r("Name") = "Crystal Gayle"
r("Address") = "The World"
t.Rows.Add(r)

For Each r In t.Rows
Debug.WriteLine(r("Name") + " - " + r("Address"))
Next

''Add the new PK Column
t.Columns.Add("ID")
Dim i As Int32 = 0
For Each r In t.Rows
r("ID") = (i).ToString
Debug.WriteLine(r("ID") + " - " + r("Name") + " - " +
r("Address"))
i += 1
Next

--

OHM ( Terry Burns )
. . . One-Handed-Man . . .
"Geoff Jones" <ge***@NODAMNSPAM.com> wrote in message
news:40**********************@news.dial.pipex.com. ..


任何人都可以帮我解决以下问题,希望简单,问题吗?

我有一张桌子,我已连接到数据集。我希望在表格的开头添加一个新的
Hi

Can anybody help me with the following, hopefully simple, question?

I have a table which I''ve connected to a dataset. I wish to add a new


,并用增量值填充它,例如:如果表格看起来像这样:

23 56
45 87
21 67
34 09

我是d喜欢把它改成:1/2
2 45 87
3 21 67
4 34 09

实际上,我要做的是在第一栏中给
的索引键。

有人可以帮忙吗?

提前致谢

Geoff
to the beginning of the table
and to fill it with incremental values e.g. if the tables looks
like this:

23 56
45 87
21 67
34 09

I''d like it to be changed into:

1 23 56
2 45 87
3 21 67
4 34 09

In fact, what I''m trying to do is to give the table an index key in the first column.

Can anybody help?

Thanks in advance

Geoff





这篇关于问:向数据集添加列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆