从Access DB读取一条记录 [英] Reading one record from an Access DB

查看:99
本文介绍了从Access DB读取一条记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经启动了一些代码,但不知道如何获得anwser。这是

代码:


我需要字段中的前四个字符数据(TextName)来获取名称

来自DB并将名称放回TextName。


Dim conn As New

System.Data.OleDb.OleDbConnection(" Provider = Micros oft) .Jet.OLEDB.4.0;数据

source = C:\ BMActivityReporting.mdb; Persist Security Info = False")


Dim sSQL As String = select * from User Where UserNo = &安培;中(TextName.Text,

1,4)


conn.Open()


Dim da As新的System.Data.OleDb.OleDbDataAdapter(sSQL,conn)


尝试


TextName.Text = da。


我不知道如何完成或者我是否朝着正确的方向前进。


谢谢,


Steve

I''ve started some code but do not know how to get the anwser. Here is the
code:

I need the first four characters of data in a field (TextName) to get a name
from a DB and put the name back into TextName.

Dim conn As New
System.Data.OleDb.OleDbConnection("Provider=Micros oft.Jet.OLEDB.4.0;Data
source=C:\BMActivityReporting.mdb;Persist Security Info=False")

Dim sSQL As String = "select * from User Where UserNo=" & Mid(TextName.Text,
1, 4)

conn.Open()

Dim da As New System.Data.OleDb.OleDbDataAdapter(sSQL, conn)

Try

TextName.Text = da.

I do not know how to finish or if I''m headed in the right direction.

THanks,

Steve

推荐答案

DataAdapter对你想要的东西有点过分。

你想要一个Command对象,在这种情况下,是OleDbCommand 。

你想使用ExecuteScalar()方法。

DataAdapter is overkill for what you want.
You want a Command object, in this case, OleDbCommand.
You want to use the ExecuteScalar() method.


我想我把一切都搞定了。


这是在

调试器中观看时SQL语句的字符串:


" select * from User Where UserNo =''0000''"


表User中有UserNo =''0000''(文本类型)的记录。


da.ExecuteScalar()在Try中完成..


我不知道如何获得这个例子的价值;有一个execption。


如何获得例外的价值?


谢谢,


史蒂夫

Steven Nagy < le ********* @ hotmail.comwrote in message

news:11 ********************* *@m73g2000cwd.googlegr oups.com ...
I think I set everything up ok.

Here is the string for the SQL statement take while watching in the
debugger:

"select * from User Where UserNo=''0000''"

There is a record with UserNo=''0000'' (Text type) in a table User.

the da.ExecuteScalar() completes within a Try..

I do not know how to get the value for the exeption; there is an execption.

How do I get the value for the exception?

THanks,

Steve
"Steven Nagy" <le*********@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...

DataAdapter对你想要的东西来说太过分了。

你想要一个Command对象,这种情况下,OleDbCommand。

您想使用ExecuteScalar()方法。
DataAdapter is overkill for what you want.
You want a Command object, in this case, OleDbCommand.
You want to use the ExecuteScalar() method.



好的,我我很受欢迎。


我想出了如何获得msgbox的异常。


我在FROM中收到错误条款。


希望我明白这一点:)


如果有人有想法让我知道。


谢谢,

史蒂夫

" Stephen Plotnick" < sp ******* @ groupcbf.com写信息

新闻:va *********************** *******@giganews.com ...
OK, I''m exceited.

I figured out how to get the exception to a msgbox.

I''m getting an error in the FROM Clause.

Hopefully I figure that out:)

If someone has an idea let me know.

THanks,
Steve
"Stephen Plotnick" <sp*******@groupcbf.comwrote in message
news:va******************************@giganews.com ...

>我想我把一切都搞定了。


这是在

调试器中观看时SQL语句的字符串:


" select * from User Where UserNo =''0000' '"


表User中有UserNo =''0000''(文本类型)的记录。


da .ExecuteScalar()在Try中完成..


我不知道如何获取exeption的值;有一个

execption。


如何获得异常的值?


谢谢,


史蒂夫

" Steven Nagy" < le ********* @ hotmail.comwrote in message

news:11 ********************* *@m73g2000cwd.googlegr oups.com ...
>I think I set everything up ok.

Here is the string for the SQL statement take while watching in the
debugger:

"select * from User Where UserNo=''0000''"

There is a record with UserNo=''0000'' (Text type) in a table User.

the da.ExecuteScalar() completes within a Try..

I do not know how to get the value for the exeption; there is an
execption.

How do I get the value for the exception?

THanks,

Steve
"Steven Nagy" <le*********@hotmail.comwrote in message
news:11**********************@m73g2000cwd.googlegr oups.com...

> DataAdapter对你想要的东西来说太过分了。
你想要一个Command对象,在这种情况下,OleDbCommand。
你想使用ExecuteScalar()方法。
>DataAdapter is overkill for what you want.
You want a Command object, in this case, OleDbCommand.
You want to use the ExecuteScalar() method.




这篇关于从Access DB读取一条记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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