使用字段名称中的空格更新表 [英] updating a table with a space in the field name

查看:92
本文介绍了使用字段名称中的空格更新表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试使用以下语句更新其字段我更改

的表时出现VB错误:


dcUpdate.Dataset.Tables( 0).Rows(0)(用户名)= Me.textbox1.Text

如果我将字段名称更改为UserName,表中的一个单词和

在上面的陈述中,它有效......


实际上,我不能这样做,因为用户已经有了一份

这个数据库...


我试过([用户名]),没有工作......

我尝试过使用字段编号(即行(0)(2)),没有工作


即使我不更新该字段更新另一个单词,

我仍​​然得到错误,因为声明:

dcUpdate.Adapter.Update(dcUpdate.Dataset," users")

在内部构建一个更新SQL,其中包含字段''用户名''

和错误......


任何指导?


谢谢......


Eych

I get a VB error when I try to update a table whose field I change
with the following statement:

dcUpdate.Dataset.Tables(0).Rows(0)("User Name") = Me.textbox1.Text
if I change the field name to "UserName", one word, in the table and
in the statement above, it works...

realistically, I can''t do this since the users already have a copy of
this database...

i''ve tried ("[User Name]"), didn''t work...
i''ve tried using the field number (i.e., Rows(0)(2)), didn''t work

even if I don''t update that field and update another that is one word,
I still get the error because the statement:
dcUpdate.Adapter.Update(dcUpdate.Dataset, "users")
internally builds an Update SQL that includes the field ''User Name''
and errors...

any guidance?

thanks...

Eych

推荐答案

Eych ,


您是否已经尝试过这个?
Eych,

Did you try this already?
dcUpdate.Dataset.Tables(0).Rows(0)(" User Name")= Me。 textbox1.Text
dcUpdate.Dataset.Tables(0).Rows(0)("User Name") = Me.textbox1.Text




2个空格

Cor



2 spaces

Cor


代替调用dcUpdate.Adapter.Update(dcUpdate.Dataset," users")

并让VB自动生成Update语句,我使用

创建了UpdateCommand属性,因此能够使用括号...

dcUpdate.Adapter.UpdateCommand =新的OleDbCommand("更新用户SET

[用户名] =?在哪里LinkID =?",dcUpdate.Connection)

dcUpdate.Adapter.UpdateCommand.Parameters.Add(新

OleDbParameter(" Name",OleDbType) .Char,50))

dcUpdate.Adapter.UpdateCommand.Parameters.Add(New OleDbParameter(" ID",

OleDbType.Integer,2))


dcUpdate.Adapter.UpdateCommand.Parameters(0).Value = Me.textbox1.Text

dcUpdate.Adapter.UpdateCommand.Parameters(1).Value = Me。 tmpUserID


dcUpdate.Connection.Open()

dcUpdate.Adapter.UpdateCommand.ExecuteNonQuery()

ey ****** @ hotmail.com (Eych)在留言中写道:< 9a ********* *****************@posting.google。 com> ...
instead of calling dcUpdate.Adapter.Update(dcUpdate.Dataset, "users")
and having VB auto-generate the Update statement, I created it with
the UpdateCommand property, thus being able to use brackets...
dcUpdate.Adapter.UpdateCommand = New OleDbCommand("UPDATE user SET
[User Name] = ? WHERE LinkID = ?", dcUpdate.Connection)

dcUpdate.Adapter.UpdateCommand.Parameters.Add(New
OleDbParameter("Name", OleDbType.Char, 50))
dcUpdate.Adapter.UpdateCommand.Parameters.Add(New OleDbParameter("ID",
OleDbType.Integer, 2))

dcUpdate.Adapter.UpdateCommand.Parameters(0).Value = Me.textbox1.Text
dcUpdate.Adapter.UpdateCommand.Parameters(1).Value = Me.tmpUserID

dcUpdate.Connection.Open()
dcUpdate.Adapter.UpdateCommand.ExecuteNonQuery()

ey******@hotmail.com (Eych) wrote in message news:<9a**************************@posting.google. com>...
当我尝试使用以下语句更新其字段我更改的表格时出现VB错误:

dcUpdate.Dataset。表(0)。行(0)(用户名)= Me.textbox1.Text

如果我将字段名称更改为UserName,表中的一个单词和<在上面的陈述中,它有效......

实际上,我不能这样做,因为用户已经有了这个数据库的副本......

我已经尝试过([用户名]),没有工作......
我尝试过使用字段编号(即行(0)( 2)),没有工作

即使我不更新该字段并更新另一个单词,
我仍然得到错误,因为声明:
dcUpdate.Adapter.Update(dcUpdate.Dataset," users")
在内部构建一个更新SQL,其中包含用户名字段和错误......
<任何指导?

谢谢......
Eych
I get a VB error when I try to update a table whose field I change
with the following statement:

dcUpdate.Dataset.Tables(0).Rows(0)("User Name") = Me.textbox1.Text
if I change the field name to "UserName", one word, in the table and
in the statement above, it works...

realistically, I can''t do this since the users already have a copy of
this database...

i''ve tried ("[User Name]"), didn''t work...
i''ve tried using the field number (i.e., Rows(0)(2)), didn''t work

even if I don''t update that field and update another that is one word,
I still get the error because the statement:
dcUpdate.Adapter.Update(dcUpdate.Dataset, "users")
internally builds an Update SQL that includes the field ''User Name''
and errors...

any guidance?

thanks...

Eych



Eych,


你有没有理由向新闻组提出这个问题?并且

比告诉答案是完全不同的解决方案?您的问题是

更新数据库并且您直接在数据库中显示更新项目的解决方案

完全绕过数据行。


我告诉这个是因为有些人在新闻组中搜索并找到一个像你这样的解决方案,当它是关于一个

数据集/表时不适合这个问题。


Cor
Eych,

Did you had any reason that you asked this question to the newsgroup and
than tell that the answer is a total different solution? Your question was
updating a datarowitem and you show a solution for an update of an item
directly in the database bypassing the datarow completly.

I tell this because some people search in newsgroups and find than a
solution like yours which does not fit the problem when it is about a
dataset/table.

Cor


这篇关于使用字段名称中的空格更新表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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