将表添加到Component中的DataSet [英] Adding Tables to DataSet in Component

查看:54
本文介绍了将表添加到Component中的DataSet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,


我正在尝试创建一个数据集作为组件,使其可以从所有

表单中访问。到目前为止,我在组件设计器中使用了以下代码:

继承System.ComponentModel.Component

Dim _TryDs as dataSet = NewTry


公共属性dataSet()as dataSet

获取

返回Me._TryDs

结束获取

设置(ByVal值为数据集)

Me._TryDs =价值

结束集

结束财产

现在我不知道如何添加2个表。我创建了2个子点

" createTableA"和createTableB并在初始化组件行之后添加了命令

createTableA()

createTableB()




当我尝试引用该组件时,DS被识别,但表格

不是。我知道我在这里遗漏了一些东西。有人可以帮忙吗?

谢谢,

克劳斯

Hi all,

I''m trying to create a dataset as a component to make it accessable from all
forms. I have used that following code so far in the component designer:

Inherits System.ComponentModel.Component
Dim _TryDs As dataSet = NewTry

Public Property dataSet() As dataSet
Get
Return Me._TryDs
End Get
Set(ByVal Value As dataSet)
Me._TryDs = Value
End Set
End Property

Now I have no idea how to add the 2 tables. I have created 2 subs
"createTableA" and "createTableB" and added the commands
createTableA()
createTableB()
after the initialize component line.

When I try to reference the component the DS is recognized but the tables
are not. I know I''m missing something here. Can anybody help?
Thanks,
Claus

推荐答案

Cjobes,


这个我曾经为某人做过的最简单的样品给你一个想法吗?


\\\

Public Class MyDataset

继承DataSet

Sub New()

MyBase.new()

Dim dt As New DataTable(TableKlaus)

Me.Tables.Add(dt)

dt.Columns.Add(" Klaus")

dt.Columns.Add(" Cor")

End Sub

Public ReadOnly Property TableKlaus()As DataTable

获取

返回Me.Tables(TableKlaus)

结束获取

结束物业

结束班级

///


dim ds as new MyDataset

dim dt as datatable = ds.TableKlaus


我希望这会给出一些想法吗?


Cor


" cjobes" < CJ **** @ nova-tech.org> schreef in bericht

新闻:O1 ************* @ TK2MSFTNGP09.phx.gbl ...
Cjobes,

Does this most simple sample that I once made for somebody give you an idea?

\\\
Public Class MyDataset
Inherits DataSet
Sub New()
MyBase.new()
Dim dt As New DataTable("TableKlaus")
Me.Tables.Add(dt)
dt.Columns.Add("Klaus")
dt.Columns.Add("Cor")
End Sub
Public ReadOnly Property TableKlaus() As DataTable
Get
Return Me.Tables("TableKlaus")
End Get
End Property
End Class
///

dim ds as new MyDataset
dim dt as datatable = ds.TableKlaus

I hope this gives some ideas?

Cor

"cjobes" <cj****@nova-tech.org> schreef in bericht
news:O1*************@TK2MSFTNGP09.phx.gbl...
大家好,

我正在尝试创建一个数据集作为组件,使其可以从
所有形式访问。到目前为止,我在组件设计器中使用了以下代码:

继承System.ComponentModel.Component
Dim _TryDs as dataSet = NewTry

公共属性dataSet()作为dataSet
获取
返回Me._TryDs
结束获取
设置(ByVal值为数据集)
Me._TryDs = Value
结束集结束财产

现在我不知道如何添加2个表。我创建了2个子/
createTableA和createTableB并在初始化组件行之后添加了命令
createTableA()
createTableB()
当我尝试引用组件时,DS被识别但是表格
不是。我知道我在这里遗漏了一些东西。有人可以帮忙吗?
谢谢,
克劳斯
Hi all,

I''m trying to create a dataset as a component to make it accessable from
all
forms. I have used that following code so far in the component designer:

Inherits System.ComponentModel.Component
Dim _TryDs As dataSet = NewTry

Public Property dataSet() As dataSet
Get
Return Me._TryDs
End Get
Set(ByVal Value As dataSet)
Me._TryDs = Value
End Set
End Property

Now I have no idea how to add the 2 tables. I have created 2 subs
"createTableA" and "createTableB" and added the commands
createTableA()
createTableB()
after the initialize component line.

When I try to reference the component the DS is recognized but the tables
are not. I know I''m missing something here. Can anybody help?
Thanks,
Claus



Cor,


非常感谢。我开始明白了这一点。我假设您的样本

代码进入组件代码。我还有两个问题:

我需要创建2个表。我会在同一个公共课上这样做吗?另外,

你能给我一个简短的样本,我需要在表格中创建

和2个表的实例吗?

实际上还有一个问题。如果我用一个

表格中的数据填充表格,然后以另一种形式创建表格的实例,那么数据

仍然存在吗?


谢谢,

克劳斯


" Cor Ligthert" <无************ @ planet.nl>在消息中写道

新闻:Oc ************** @ TK2MSFTNGP15.phx.gbl ...
Cor,

Thanks a lot. I''m starting to understand this. I assume that your sample
code goes into the component code. I have two more questions:
I need to create 2 tables. Would I do this in the same public class? Also,
could you give me a short sample of what I need to do in a form to create
and instance of the 2 tables?

Actually there is one more question. If I fill the tables with data in one
form and then create an instance of the tables in another form will the data
still be there?

Thanks,
Claus

"Cor Ligthert" <no************@planet.nl> wrote in message
news:Oc**************@TK2MSFTNGP15.phx.gbl...
Cjobes,
这个我曾经为某人制作的最简单的样本给你一个
的想法吗?
\\\
公共类MyDataset
继承DataSet
Sub New()
MyBase.new()
Dim dt As New DataTable(" TableKlaus")
Me.Tables.Add(dt)
dt.Columns。添加(Klaus)
dt.Columns.Add(Cor)
End Sub
Public ReadOnly属性TableKlaus()作为DataTable
获取
返回Me.Tables(TableKlaus)
结束获取
最终产品
///

dim ds as new MyDataset
dim dt as datatable = ds.TableKlaus

我希望这能给出一些想法吗?

Cor

" cjobes" < CJ **** @ nova-tech.org> schreef in bericht
新闻:O1 ************* @ TK2MSFTNGP09.phx.gbl ...
Cjobes,

Does this most simple sample that I once made for somebody give you an idea?
\\\
Public Class MyDataset
Inherits DataSet
Sub New()
MyBase.new()
Dim dt As New DataTable("TableKlaus")
Me.Tables.Add(dt)
dt.Columns.Add("Klaus")
dt.Columns.Add("Cor")
End Sub
Public ReadOnly Property TableKlaus() As DataTable
Get
Return Me.Tables("TableKlaus")
End Get
End Property
End Class
///

dim ds as new MyDataset
dim dt as datatable = ds.TableKlaus

I hope this gives some ideas?

Cor

"cjobes" <cj****@nova-tech.org> schreef in bericht
news:O1*************@TK2MSFTNGP09.phx.gbl...
大家好,
我正在尝试创建一个数据集作为一个组件,使其可以从
所有形式访问。到目前为止,我在组件设计器中使用了以下代码:

继承System.ComponentModel.Component
Dim _TryDs as dataSet = NewTry

公共属性dataSet()作为dataSet
获取
返回Me._TryDs
结束获取
设置(ByVal值为数据集)
Me._TryDs = Value
结束集结束财产

现在我不知道如何添加2个表。我创建了2个子/
createTableA和createTableB并在初始化组件行之后添加了命令
createTableA()
createTableB()
当我尝试引用组件时,DS被识别但是
表不是。我知道我在这里遗漏了一些东西。任何人都可以帮忙吗?
谢谢,
克劳斯
Hi all,

I''m trying to create a dataset as a component to make it accessable from
all
forms. I have used that following code so far in the component designer:

Inherits System.ComponentModel.Component
Dim _TryDs As dataSet = NewTry

Public Property dataSet() As dataSet
Get
Return Me._TryDs
End Get
Set(ByVal Value As dataSet)
Me._TryDs = Value
End Set
End Property

Now I have no idea how to add the 2 tables. I have created 2 subs
"createTableA" and "createTableB" and added the commands
createTableA()
createTableB()
after the initialize component line.

When I try to reference the component the DS is recognized but the tables are not. I know I''m missing something here. Can anybody help?
Thanks,
Claus




Claus,
Claus,
非常感谢。我开始明白了这一点。我假设你的样本代码进入了组件代码。


你不能继承两次但是继承的数据集确实是这个

已经在本页顶部看到了
http://msdn.microsoft。 com / library / de ... classtopic.asp

我还有两个问题:
我需要创建2个表。我会在同一个公共课上这样做吗?另外,你可以给我一个简短的样本,我需要在表格中创建
和2个表的实例吗?
Thanks a lot. I''m starting to understand this. I assume that your sample
code goes into the component code.
You cannot inherit twice however the dataset that is inherited does that
already see in top of this page
http://msdn.microsoft.com/library/de...classtopic.asp
I have two more questions:
I need to create 2 tables. Would I do this in the same public class? Also,
could you give me a short sample of what I need to do in a form to create
and instance of the 2 tables?




你所做的一切都取决于你,但为什么不呢。我在一个新的样本中展示了上面的东西

然而你走多远又取决于你。我做了一个非常简单的示例

,我在这个额外的数据表中加载一个数据表作为

方法,并在数据网格上显示该表


\\\需要表单上带有数据网格的新项目

Private Sub Form1_Load(ByVal sender As Object,_

ByVal e As Hand.EventArgs)处理MyBase.Load

Dim ds作为新的MyDataset

对于我作为整数= 0到10

ds.KlausTableAddNew(新的Object(){i.ToString,ChrW(i + 65)})

下一页

DataGrid1.DataSource = ds.TableKlaus

End Sub

结束班

公共类MyDataset

继承数据集

Sub New()

MyBase.new()

Dim dt As New DataTable(" TableKlaus")

Me.Tables.Add(dt)

dt .Columns.Add(" Klaus")

dt.Columns.Add(" Cor")

dt = New DataTable(" TableCor")

Me.Tables.Add(dt)

dt.Columns。添加(John)

dt.Columns.Add(" Herfried")

End Sub

Public ReadOnly Property TableKlaus()作为DataTable

获取

返回Me.Tables(TableKlaus)

结束获取

结束财产

Public ReadOnly属性TableCor()As DataTable

获取

返回Me.Tables(TableCor)

结束获取

结束财产

Public Sub KlausTableAddNew(ByVal obj As Object())

Dim dr As DataRow = Me.TableKlaus.NewRow

dr.ItemArray = obj

Me.TableKlaus.Rows.Add(dr)

End Sub

End Class

///


我希望这有点帮助吗?


Cor




Everything you do is up to you, however why not. I showed the things above
in a new sample bellow however how far you go is again up to you. I made a
very simple sample where I made an extra datatable and load a datatable as
method in this extra and showed that table on a datagrid

\\\needs new project with a datagrid on the form
Private Sub Form1_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles MyBase.Load
Dim ds As New MyDataset
For i As Integer = 0 To 10
ds.KlausTableAddNew(New Object() {i.ToString, ChrW(i + 65)})
Next
DataGrid1.DataSource = ds.TableKlaus
End Sub
End Class
Public Class MyDataset
Inherits DataSet
Sub New()
MyBase.new()
Dim dt As New DataTable("TableKlaus")
Me.Tables.Add(dt)
dt.Columns.Add("Klaus")
dt.Columns.Add("Cor")
dt = New DataTable("TableCor")
Me.Tables.Add(dt)
dt.Columns.Add("John")
dt.Columns.Add("Herfried")
End Sub
Public ReadOnly Property TableKlaus() As DataTable
Get
Return Me.Tables("TableKlaus")
End Get
End Property
Public ReadOnly Property TableCor() As DataTable
Get
Return Me.Tables("TableCor")
End Get
End Property
Public Sub KlausTableAddNew(ByVal obj As Object())
Dim dr As DataRow = Me.TableKlaus.NewRow
dr.ItemArray = obj
Me.TableKlaus.Rows.Add(dr)
End Sub
End Class
///

I hope this helps a little bit?

Cor



这篇关于将表添加到Component中的DataSet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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