如何使用params与insertCmd for DataAdapter? [英] howto use params with insertCmd for DataAdapter?

查看:57
本文介绍了如何使用params与insertCmd for DataAdapter?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,


刚开始使用.net。我有一个vb.net应用程序,我

连接到Access mdb。我使用工具箱(conn1)中的连接组件

,工具箱(da1)中的数据适配器组件,并创建一个类型化数据集(ds1)和

填充表单(grd1)上的网格。一切正常,

我可以在网格中看到来自Access mdb的数据。但现在我想要向mdb添加一条记录。


在数据适配器da1中,我在属性表中看到了

select命令(selcmd1),插入命令(insCmd1)和

删除命令。对于insCmd1,我将连接设置为

conn1。然后我想设置参数。我在Access表中有3个
字段,fld1(文本),fld2(数字),

fld3(日期)。在da1的Paramters对话框中,对于

insCmd1,我看到了一个Source Column。字段,值字段和

a参数名称领域。在我的vb表单上,我有3个

文本框,txt1,txt2,txt3。我希望parm1在txt1中具有

值,parm2具有txt2的值,parm3用于txt3。

问题:我在源列字段中放置了什么?对于

parm1?如何告诉它检索

txt1.text的值?等等。


然后我在表单上有一个按钮(btn1),我点击它来进行插入操作。
执行插入操作。我不清楚用于执行此操作的

语法。我还要说

insCmd1.Paramters.Add(txt1)

....

da1.SelectCmd = insCmd1

da1.InsertCommand = insCmd1.something


嗯,这是我尝试过的,没有任何成功。任何

建议如何做到这一点将不胜感激。


谢谢,

丰富

Greetings,

Just starting out with .net. I have a vb.net app where I
connect to an Access mdb. I use a connection component
from the tool box (conn1), a data adapter component from
the toolbox (da1) and create a typed dataset (ds1) and
populate a grid on a form (grd1). This all works fine and
I can see data from the Access mdb in the grid. But now I
want to add a record to the mdb.

In the data adapter da1 I see in the property sheet a
select command (selcmd1), insert command (insCmd1) and
delete command. For insCmd1 I set the connection to
conn1. Then I want to set the parameters. I have 3
fields in the Access table, fld1 (text), fld2 (number),
fld3 (date). In the Paramters dialog box of da1 for
insCmd1 I see a "Source Column" field, a "Value" field and
a "Parameter Name" field. On my vb form I have 3
textboxes, txt1, txt2, txt3. I want parm1 to have the
value in txt1, parm2 has value for txt2, parm3 for txt3.
Question: what do I put in the "Source Column field" for
parm1? How do I tell it to retrieve the value of
txt1.text? and so on.

Then I have a button (btn1) on the form which I click to
carry out the insert operation. I am not clear on the
syntax for carrying this out. Do I still have to say
insCmd1.Paramters.Add(txt1)
....
da1.SelectCmd = insCmd1
da1.InsertCommand = insCmd1.something

Well, this is what I tried without any success. Any
advice how to do this would be greatly appreciated.

Thanks,
Rich

推荐答案

Hi Rich,


在adonet组中有些人讨厌这个。


但是要开始这样做(忘记插入,更新和

删除命令一段时间)


DirectCast(BindingContext(ds.tables(0) ),CurrencyManager)。EndCurrentEdit()

Dim da As New OleDbDataAdapter(" OriginalSelectString",connection)

Dim cb As New OleDbCommandBuilder(da)

如果ds.HasChanges然后

da.Update(ds)

结束如果


使用困难的选择字符串命令构建器可能会给出错误。


您可能忘记了da并在命令构建器中将其替换为

da1


我希望这有帮助吗?


Cor
Hi Rich,

In the adonet group are some guys who hate this.

But to start just do this (forget the insert, the update and the
deletecommand a while)

DirectCast(BindingContext(ds.tables(0)), CurrencyManager).EndCurrentEdit()
Dim da As New OleDbDataAdapter("OriginalSelectString",connection )
Dim cb As New OleDbCommandBuilder(da)
If ds.HasChanges Then
da.Update(ds)
End If

With difficult select strings the commandbuilder can give errors.

You can probably forgot that da and replace it in the commandbuilder with
da1

I hope this helps?

Cor

刚开始使用.net。我有一个vb.net应用程序,我连接到Access mdb。我使用工具箱(conn1)中的连接组件,来自工具箱(da1)的数据适配器组件,并创建一个类型化数据集(ds1)并在表单上填充网格(GRD1)。这一切都很好,我可以看到网格中的Access mdb数据。但是现在我想要向mdb添加一条记录。

在数据适配器da1中,我在属性表中看到了一个
select命令(selcmd1),insert命令(insCmd1) )和
删除命令。对于insCmd1,我将连接设置为
conn1。然后我想设置参数。我在Access表中有3个字段,fld1(文本),fld2(数字),
fld3(日期)。在da1 for
insCmd1的Paramters对话框中,我看到一个Source Column。字段,值字段和
a参数名称领域。在我的vb表单上,我有3个文本框,txt1,txt2,txt3。我希望parm1在txt1中具有
值,parm2具有txt2的值,parm3用于txt3。
问题:我在源列字段中放置了什么?对于parm1?如何告诉它检索
txt1.text的值?等等。然后我在表单上有一个按钮(btn1),我点击它来执行插入操作。我不清楚执行此操作的
语法。我还要说
insCmd1.Paramters.Add(txt1)
......
da1.SelectCmd = insCmd1
da1.InsertCommand = insCmd1.something
<嗯,这是我试过没有任何成功的。任何
建议如何做到这一点将不胜感激。

Just starting out with .net. I have a vb.net app where I
connect to an Access mdb. I use a connection component
from the tool box (conn1), a data adapter component from
the toolbox (da1) and create a typed dataset (ds1) and
populate a grid on a form (grd1). This all works fine and
I can see data from the Access mdb in the grid. But now I
want to add a record to the mdb.

In the data adapter da1 I see in the property sheet a
select command (selcmd1), insert command (insCmd1) and
delete command. For insCmd1 I set the connection to
conn1. Then I want to set the parameters. I have 3
fields in the Access table, fld1 (text), fld2 (number),
fld3 (date). In the Paramters dialog box of da1 for
insCmd1 I see a "Source Column" field, a "Value" field and
a "Parameter Name" field. On my vb form I have 3
textboxes, txt1, txt2, txt3. I want parm1 to have the
value in txt1, parm2 has value for txt2, parm3 for txt3.
Question: what do I put in the "Source Column field" for
parm1? How do I tell it to retrieve the value of
txt1.text? and so on.

Then I have a button (btn1) on the form which I click to
carry out the insert operation. I am not clear on the
syntax for carrying this out. Do I still have to say
insCmd1.Paramters.Add(txt1)
...
da1.SelectCmd = insCmd1
da1.InsertCommand = insCmd1.something

Well, this is what I tried without any success. Any
advice how to do this would be greatly appreciated.



您好Cor,


谢谢期待你的答复。终于把vs.net2003加载到了我的电脑上。
我的电脑。


问题:我的数据显示在网格控件中。表单上的

文本框是未绑定的文本框。我应该将
绑定文本框到数据集吗?如果没有,我如何引用文本框,因为它们是我想要的参数

插入新记录?


再次感谢,

Rich

Hi Cor,

Thanks for your reply. Finally got vs.net2003 loaded on
my computer.

Question: My data is displayed in the grid control. The
textboxes on the form are unbound textboxes. Should I
bind the textboxes to the dataset? If not, how do I
reference the textboxes, as they are the parameters I want
to insert in the new record?

Thanks again,
Rich

-----原帖-----
Hi Rich,

在adonet组中有些人讨厌这个。

但是要开始这样做(忘记插入,更新
和删除指令一段时间)

DirectCast(BindingContext(ds.tables(0)),
CurrencyManager)。EndCurrentEdit()Dim da As New OleDbDataAdapter
(" OriginalSelectString",connection)Dim cb As New OleDbCommandBuilder (da)
如果ds.HasChanges那么
da.Update(ds)
结束如果

对于困难的选择字符串,命令构建者可以给出
错误。
你可能忘了da并在
命令构建器中用da1替换它

我希望这有帮助吗?

Cor
-----Original Message-----
Hi Rich,

In the adonet group are some guys who hate this.

But to start just do this (forget the insert, the update and thedeletecommand a while)

DirectCast(BindingContext(ds.tables(0)), CurrencyManager).EndCurrentEdit()Dim da As New OleDbDataAdapter ("OriginalSelectString",connection)Dim cb As New OleDbCommandBuilder(da)
If ds.HasChanges Then
da.Update(ds)
End If

With difficult select strings the commandbuilder can give errors.
You can probably forgot that da and replace it in the commandbuilder withda1

I hope this helps?

Cor

刚开始使用.net。我有一个vb.net应用程序,其中
我连接到Access mdb。我使用工具箱(conn1)中的连接组件,来自工具箱(da1)的数据适配器组件,并创建一个类型化数据集(ds1)并在表单上填充网格(GRD1)。这一切都很好
我可以在网格中看到来自Access mdb的数据。但是
现在我想在mdb中添加一条记录。

在数据适配器da1中,我在属性表中看到了一个
select命令(selcmd1),insert命令(insCmd1) )和
删除命令。对于insCmd1,我将连接设置为
conn1。然后我想设置参数。我在Access表中有3个字段,fld1(文本),fld2(数字),
fld3(日期)。在da1 for
insCmd1的Paramters对话框中,我看到一个Source Column。字段,值字段
和参数名称字段领域。在我的vb表单上,我有3个文本框,txt1,txt2,txt3。我希望parm1在txt1中具有
值,parm2具有txt2的值,parm3用于txt3。
问题:我在源列字段中放置了什么? parm1
?如何告诉它检索
txt1.text的值?等等。然后我在表单上有一个按钮(btn1),我点击它来执行插入操作。我不清楚执行此操作的
语法。我还要说
insCmd1.Paramters.Add(txt1)
......
da1.SelectCmd = insCmd1
da1.InsertCommand = insCmd1.something
<嗯,这是我试过没有任何成功的。任何
建议如何做到这一点将不胜感激。

Just starting out with .net. I have a vb.net app where I connect to an Access mdb. I use a connection component
from the tool box (conn1), a data adapter component from
the toolbox (da1) and create a typed dataset (ds1) and
populate a grid on a form (grd1). This all works fine and I can see data from the Access mdb in the grid. But now I want to add a record to the mdb.

In the data adapter da1 I see in the property sheet a
select command (selcmd1), insert command (insCmd1) and
delete command. For insCmd1 I set the connection to
conn1. Then I want to set the parameters. I have 3
fields in the Access table, fld1 (text), fld2 (number),
fld3 (date). In the Paramters dialog box of da1 for
insCmd1 I see a "Source Column" field, a "Value" field and a "Parameter Name" field. On my vb form I have 3
textboxes, txt1, txt2, txt3. I want parm1 to have the
value in txt1, parm2 has value for txt2, parm3 for txt3.
Question: what do I put in the "Source Column field" for parm1? How do I tell it to retrieve the value of
txt1.text? and so on.

Then I have a button (btn1) on the form which I click to
carry out the insert operation. I am not clear on the
syntax for carrying this out. Do I still have to say
insCmd1.Paramters.Add(txt1)
...
da1.SelectCmd = insCmd1
da1.InsertCommand = insCmd1.something

Well, this is what I tried without any success. Any
advice how to do this would be greatly appreciated.




.



Hi Rich,


Normaly你不需要做任何事情来插入新行,只需在底部开始输入




如果你想对它进行排序,看看数据视图,你可以把数据集和数据网格放在

之间。


肮脏的类型当然。

\\\

dim dv as new dataview(ds.tables(0))

dv.sort = " mycolumname"

datagrid.datasource = dv

///

Cor
Hi Rich,

Normaly you do not have to do nothing to insert a new row, just start typing
at the bottom.

If you want it sorted have a look at the dataview, that you can put between
your dataset and the datagrid.

Something as dirty typed of course.
\\\
dim dv as new dataview(ds.tables(0))
dv.sort = "mycolumname"
datagrid.datasource = dv
///
Cor
<谢谢你的回复。最后在我的电脑上加载了vs.net2003。

问题:我的数据显示在网格控件中。表单上的
文本框是未绑定的文本框。我应该将文本框绑定到数据集吗?如果没有,我如何引用文本框,因为它们是我想要在新记录中插入的参数?

再次感谢,
Rich


Thanks for your reply. Finally got vs.net2003 loaded on
my computer.

Question: My data is displayed in the grid control. The
textboxes on the form are unbound textboxes. Should I
bind the textboxes to the dataset? If not, how do I
reference the textboxes, as they are the parameters I want
to insert in the new record?

Thanks again,
Rich

-----原帖-----
嗨Rich,

在adonet组中有些人讨厌这个。

但是要开始这样做(忘记插入,更新
-----Original Message-----
Hi Rich,

In the adonet group are some guys who hate this.

But to start just do this (forget the insert, the update


删除命令一段时间)

DirectCast(BoundContext (ds.tables(0)),
deletecommand a while)

DirectCast(BindingContext(ds.tables(0)),


CurrencyManager)。EndCurrentEdit()


CurrencyManager).EndCurrentEdit()

Dim da As New OleDbDataAdapter
Dim da As New OleDbDataAdapter


(" OriginalSelectString",connection)


("OriginalSelectString",connection)

Dim cb As New OleDbCommandBuilder(da)
如果ds.HasChanges那么
da.Update(ds)
结束如果<对于困难的选择字符串,命令构建者可以给出
Dim cb As New OleDbCommandBuilder(da)
If ds.HasChanges Then
da.Update(ds)
End If

With difficult select strings the commandbuilder can give


错误。


您可能忘记了da并替换了我在

You can probably forgot that da and replace it in the


命令构建器中使用


commandbuilder with

da1

我希望这有帮助吗?

Cor
da1

I hope this helps?

Cor

刚开始使用.net。我有一个vb.net应用程序,我连接到Access mdb。我使用工具箱(conn1)中的连接组件,来自工具箱(da1)的数据适配器组件,并创建一个类型化数据集(ds1)并在表单上填充网格(GRD1)。这一切都很好,我可以看到网格中的Access mdb数据。但是现在我想在mdb中添加一条记录。

在数据适配器da1中,我在属性表中看到了一个
select命令(selcmd1),insert命令(insCmd1)和
删除命令。对于insCmd1,我将连接设置为
conn1。然后我想设置参数。我在Access表中有3个字段,fld1(文本),fld2(数字),
fld3(日期)。在da1 for
insCmd1的Paramters对话框中,我看到一个Source Column。字段,值字段和参数名称领域。在我的vb表单上,我有3个文本框,txt1,txt2,txt3。我希望parm1在txt1中具有
值,parm2具有txt2的值,parm3用于txt3。
问题:我在源列字段中放置了什么?对于parm1?如何告诉它检索
txt1.text的值?等等。然后我在表单上有一个按钮(btn1),我点击它来执行插入操作。我不清楚执行此操作的
语法。我还要说
insCmd1.Paramters.Add(txt1)
......
da1.SelectCmd = insCmd1
da1.InsertCommand = insCmd1.something
<嗯,这是我试过没有任何成功的。任何
建议如何做到这一点将不胜感激。

Just starting out with .net. I have a vb.net app where I connect to an Access mdb. I use a connection component
from the tool box (conn1), a data adapter component from
the toolbox (da1) and create a typed dataset (ds1) and
populate a grid on a form (grd1). This all works fine and I can see data from the Access mdb in the grid. But now I want to add a record to the mdb.

In the data adapter da1 I see in the property sheet a
select command (selcmd1), insert command (insCmd1) and
delete command. For insCmd1 I set the connection to
conn1. Then I want to set the parameters. I have 3
fields in the Access table, fld1 (text), fld2 (number),
fld3 (date). In the Paramters dialog box of da1 for
insCmd1 I see a "Source Column" field, a "Value" field and a "Parameter Name" field. On my vb form I have 3
textboxes, txt1, txt2, txt3. I want parm1 to have the
value in txt1, parm2 has value for txt2, parm3 for txt3.
Question: what do I put in the "Source Column field" for parm1? How do I tell it to retrieve the value of
txt1.text? and so on.

Then I have a button (btn1) on the form which I click to
carry out the insert operation. I am not clear on the
syntax for carrying this out. Do I still have to say
insCmd1.Paramters.Add(txt1)
...
da1.SelectCmd = insCmd1
da1.InsertCommand = insCmd1.something

Well, this is what I tried without any success. Any
advice how to do this would be greatly appreciated.




.



这篇关于如何使用params与insertCmd for DataAdapter?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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