简体   繁体   English

从VB.net中的数据库读取更新的记录

[英]Reading Updated records from database in VB.net

I am using VB.Net to read a field from a table in a database. 我正在使用VB.Net从数据库的表中读取字段。 A timer is scheduled to read the value of that field per 5 seconds. 计划安排计时器每5秒读取一次该字段的值。 I am using a data adapter to get the values in a table , first element of first row in that table is my data. 我正在使用数据适配器来获取表中的值,该表中第一行的第一个元素是我的数据。 What I observe is that if I read the data in a for loop it works fine. 我观察到的是,如果我在for循环中读取数据,则可以正常工作。 The changes made in that field value externally are reflected in the variable used to store that data. 在外部对该字段值所做的更改将反映在用于存储该数据的变量中。 But if I directly read the index 0 element of first row, variable does not reflect changes made externally to database. 但是,如果我直接读取第一行的索引0元素,则变量不会反映数据库外部所做的更改。

'----declaration---
 Dim query2 As String = "SELECT Data2 FROM DSSControl WHERE StationID LIKE 1"
 Dim MDBConnString_ As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\DrumScanningSystem.mdb;;"
Dim ds As New DataSet
Dim cnn As OleDbConnection = New OleDbConnection(MDBConnString_)

'-----use in timer


If cnn.State = ConnectionState.Closed Then
            cnn.Open()
        End If

        Dim cmd1 As New OleDbCommand(query2, cnn)
        Dim da2 As New OleDbDataAdapter(cmd1)
        da2.Fill(ds, "DSSControl")

        Dim t2 As DataTable = ds.Tables("DSSControl")
        Dim row2 As DataRow

        Dim flagvar As UInteger

        For Each row2 In t2.Rows
            flagvar = CUInt(row2(0))
        Next

this works fine but instead of for loop if i use 这工作正常,但如果我使用for循环

     row2 = t2.Rows(0) 

     flagvar = CInt(row2(0))

this does not reflect change in 'flagvar' Thanks in advance! 这并不反映'flagvar'的变化预先感谢!

please Correct to flagvar = CUInt(row2(0)) , you lose data with flagvar = CInt(row2(0)) .Perhaps this is the issue 请更正为flagvar = CUInt(row2(0)) ,使用flagvar = CInt(row2(0))会丢失数据。也许这就是问题所在

(INTEGER (整数

Integer (whole number) data from -2^31 (-2,147,483,648) through 2^31 - 1 (2,147,483,647). 从-2 ^ 31(-2,147,483,648)到2 ^ 31-1(2,147,483,647)的整数(整数)数据。 Storage size is 4 bytes. 存储大小为4个字节。

UINTEGER 勇者

Unsigned integer (whole number) data from 0 through 2^32 (4294967295) Storage size is 4 bytes.) 0到2 ^ 32之间的无符号整数(整数)数据(4294967295)存储大小为4个字节。)

Probably you are interested in non-negative values 可能您对非负值感兴趣

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM