读取数据库中的值? [英] Reading values in a database?

查看:78
本文介绍了读取数据库中的值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嘿,所以基本上我有一个包含几个表的数据库,并且这些表中的一个具有特定的列,称为"Shift",并且该列的第一行/单元格的值可能为1或2.

我要让程序执行的操作是连接到数据库,并且如果该行上的值为1,则将发生某些事情,如果该值为2,则将发生其他事情.

因此,基本上,我正在尝试读取Access数据库中单元格的值,并根据该值做些什么.

这应该很容易做到,但是我是个noobie ... =(

这是我的代码的一部分,也是我的错误尝试之一,您应该能够从中了解我正在尝试执行的操作:

Hey there, so basically I have a database with a few tables and one of those tables has a particular column, called "Shift" and the first row/cell of that column may have values 1 or 2.

What I''m trying to get my program to do is to connect to the database and if the value on that row is 1, then something is gonna happen, if the value is 2, something else is gonna happen.

So basically I''m trying to read the value of a cell in an Access database and do something according to what that value is.

This should be very easy to do but I''m a noobie... =(

Here''s a part of my code, and one of my wrong attempts, you should be able to understand what I''m trying to do from this:

Provider = "Provider=Microsoft.ACE.OLEDB.12.0;"
Source = "Data Source = Database.accdb"

Connection.ConnectionString = Provider & Source

Connection.Open()

'My wrong attempt at doing this:
If SQL = "Shift FROM Schedule WHERE ID = 1;" = 1 Then
    '.....
    '.....
ElseIf SQL = "Shift FROM Schedule WHERE ID = 1;" = 0 Then
    '....
    '.....
Else
    MsgBox("error")
End If

Connection.Close()

推荐答案

您需要执行查询,从数据库中获取结果并将其与1进行比较.
目前,您实际上只是在比较字符串值.

[ ^ ]是一个简单的示例,可以帮助您进一步进行操作.
You need to execute the query, get the result back from the database and compare it against 1.
At the moment you are actually just comparing the string value.

This[^] is a simple example that might help you proceed further.


这篇关于读取数据库中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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