如何从Access数据库获取字符串? [英] How do I get a string from an Access database?

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

问题描述

我已经交给一个Access数据库,有3列:名称,类别,电子邮件。我想要做的是把匹配给定类别的所有电子邮件作为字符串输出。

I've been handed an Access database with 3 columns: Name, category, e-mail. What I'm trying to do is get out, as strings, all of the e-mails that match a given category.

我正在学习它的过程中,我有一点了解SQL。我已经设法解析这个位的代码,填充一个可视网格的名字

I have a slight understanding SQL as I'm in the process of learning it. I've managed to churn out this bit of code, which populates a visual grid with the first names

Dim comm As New OleDbConnection("Provider=Microsoft.Jet.OleDb.4.0;Data Source=.\AddressBook.mdb")
Dim addda As New OleDbDataAdapter("SELECT FirstName FROM Contacts", comm)
Dim dd As New DataTable("Name")
addda.Fill(dd)
DataGridView2.DataSource = dd


$ b b

所以我觉得我相当接近,但我不知道如何获得名字列表进入字符串(或字符串数​​组)。

So I feel I'm getting fairly close, but I can't figure out how to get that list of first names to go into a string (or array of strings). All of the online tutorials and books I find seem to go over just displaying the data in a dataview.

指向正确的方向?

推荐答案

尝试:

Dim Names As New List(Of String)

Using comm As New OleDbConnection("Provider...")
  comm.Open()
  Using cmd As New OleDbCommand("SELECT FirstName FROM Contacts", comm)
    Using reader As OleDbDataReader = cmd.ExecuteReader
      While reader.Read
        Names.Add(reader("FirstName").ToString)
      End While
    End Using
  End Using
End Using

使用格式会自动数据对象。

The Using format will automatically dispose of your data objects.

这篇关于如何从Access数据库获取字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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