如何更新现有的Sql Ce记录 [英] How Do I Update Existing Sql Ce Records

查看:109
本文介绍了如何更新现有的Sql Ce记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hie

我的名字是Jan Makopa。

我正在开展一个项目来阅读和显示来自MODBUS设备的信息。我想以编程方式在vb.net中创建一个SQL CE数据库。该数据库将包含custimized字段。到目前为止,我已经实现了以下目标:

- 以编程方式创建SQLCE

- 创建表和列

- 删除记录

-Refreshing数据库



问题:

我没有通过SQL来编辑现有记录

我目前用于UPDATING的源代码如下:

**************************** ***************************************

Dim描述As String =你好代码项目



Dim Row()As Data.DataRow

Row = ds.Tables(Modbus)。Select(CoilID = 54)

行(0)(注册)=说明

cmd.ExecuteNonQuery()

****** ************************************************** ********



^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Modbus的名称是表

CoilID是KeyID列的名称

Registr是n我想要改变的列的名字

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

我只是觉得我可以澄清它让它变得容易对于那些愿意帮助我b $ b b的人来说。



***************** ***********************************************

当我尝试更新它时会产生以下错误:

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^

附加信息:ExecuteNonQuery:连接属性尚未初始化。

^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^^^^^^^^^^

问题是我不知道什么连接属性没有在静止中初始化



我恳请你帮我解决我面临的问题。请更新记录的样本足够好。我已经用尽了我们心爱的搜索引擎谷歌的一些链接,这就是为什么我来到这个论坛寻求你的帮助。



提前谢谢你绅士

Hie
My name is Jan Makopa.
I am working torwards a project to read and display information from MODBUS device. I want to create an SQL CE database in vb.net programmatically. The database will contain custimized fields. So far i have achieved the following:
- Creating SQLCE Programatically
- Creating Tables and Columns
- Deleting Records
-Refreshing Database

Problem:
I am failing to pass a quiry to SQL to edit existing record
The source code i currently have for UPDATING is as follows:
***************************************************************
Dim Description As String = "Hello Code Project"

Dim Row() As Data.DataRow
Row = ds.Tables("Modbus").Select("CoilID = 54")
Row(0)("Register") = Description
cmd.ExecuteNonQuery()
****************************************************************

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Modbus is the name of the Table
CoilID is the name of the KeyID column
Registr is the name of the column where i want to make changes
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
That i just thought i could clarify so that it makes it easy for someone who is willing to
assist me.

************************************************************
when i try to update it gives the following error is generated:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Additional information: ExecuteNonQuery: Connection property has not been initialized.
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Problem is i dont know what connection property has not been "initialized" in the quiery

I was kindly requesting you to assist me with the problem that i am facing. Please a sample of updating a record is good enough. I have exhausted a number of links from our beloved search engine "Google" and that is why i came to this forum to seek for your assistance.

Thank you in advance gentleman

推荐答案

Hie

我设法从你给我的链接中提取某些信息并且它有效。我刚刚创建了一个示例数据库,并提供了以下更新查询:

尝试

Dim描述为String = TextBox4.Text



Dim Row()As Data.DataRow

Row = ds.Tables(Persons)。Select(PersonsID = 54)

Row( 0)(名称)=说明





Dim q作为新的SqlCeCommand(UPDATE Persons SET Name = @ Name,Phone = @Phone,其中PersonsID = 54,conn)

For i = 0 to ds.Tables(Persons)。Rows.Count - 1









q.Parameters.Add(新的SqlCeParameter(@ Name,ds.Tables(Persons)。行(i)(名称)))

q.Parameters.Add(新的SqlCeParameter(@ Phone,ds.Tables(Persons)。行(i)(电话) )))



q.ExecuteNonQuery()

下一页





Catch ex As Exception

MsgBox(ex.Message)

结束尝试

结束次级

最后,经过两天的挠头之后。这真的很好,多亏你,感谢你。
Hie
I have managed to extract certain information from the link you gave me and it worked. I just created a sample database and i put the following update query:
Try
Dim Description As String = TextBox4.Text

Dim Row() As Data.DataRow
Row = ds.Tables("Persons").Select("PersonsID = 54")
Row(0)("Name") = Description


Dim q As New SqlCeCommand("UPDATE Persons SET Name=@Name,Phone=@Phone where PersonsID = 54", conn)
For i = 0 To ds.Tables("Persons").Rows.Count - 1




q.Parameters.Add(New SqlCeParameter("@Name", ds.Tables("Persons").Rows(i)("Name")))
q.Parameters.Add(New SqlCeParameter("@Phone", ds.Tables("Persons").Rows(i)("Phone")))

q.ExecuteNonQuery()
Next


Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
At last, after two days of scratching my head. It really worked fine, thanks to you man.


这篇关于如何更新现有的Sql Ce记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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