How to copy a selected database record into a set of string variables

U

Ulf.Kriemeyer

Hello everybody,

I'd like to write code in order to find a specific record in a
database (*.mdf) connected to my VB Project and then have the
corresponding record being transferred to an array of string
variables. As the database consists of 11 columns (including the
primary key), and as I would like to let select a specific record by
its primary key, 10 string variables would be needed to capture the
entire database record.
By double clicking the *.xsd icon in the solution explorer, I opened
the dataset designer. After right clicking on the TableAdapter and
choosing the “TableAdapter Configuration Wizard”, I succeed to setup
a query with SQL statements (SELECT, FROM, WHERE statements), but I
didn’t arrive to write some working code to take advantage of this
query. Then I tried to use the SQL statements right in the VB code
itself, but wasn’t successful either. At the beginning I thought it
would be quite no big deal, but it turned out to be very tricky for
me.
Unfortunately, I didn’t find any useful solution at MSDN. Therefore I
would be very grateful for any advice how to write code so that a
specific database record will be copied to an array of string
variables.

Thanks in advance
Ulli
 
D

dot nyet

On Mon, 9 Jun 2008 16:06:35 -0700 (PDT), (e-mail address removed) wrote:
in said:
Hello everybody,

I'd like to write code in order to find a specific record in a
database (*.mdf) connected to my VB Project and then have the
corresponding record being transferred to an array of string
variables. As the database consists of 11 columns (including the
primary key), and as I would like to let select a specific record by
its primary key, 10 string variables would be needed to capture the
entire database record.
By double clicking the *.xsd icon in the solution explorer, I opened
the dataset designer. After right clicking on the TableAdapter and
choosing the “TableAdapter Configuration Wizard”, I succeed to setup
a query with SQL statements (SELECT, FROM, WHERE statements), but I
didn’t arrive to write some working code to take advantage of this
query. Then I tried to use the SQL statements right in the VB code
itself, but wasn’t successful either. At the beginning I thought it
would be quite no big deal, but it turned out to be very tricky for
me.
Unfortunately, I didn’t find any useful solution at MSDN. Therefore I
would be very grateful for any advice how to write code so that a
specific database record will be copied to an array of string
variables.

Thanks in advance
Ulli

First, you've confused tables and databases. If your database only
contains a single table then no harm (well sort of) but it sounds like
you want to serialize the data in a table or tables in your database.

You could use Microsoft's XML methods but that would leave you dependent
on their proprietary code. More that likely it would be much simpler to
roll your own.

Simply run your query and then output the values into a tab delimited
file. This has the added advantage of being ready for insert using the
various Bulk Insert methods provided but you can also of course roll
your own here as well.

Post back if you need assistance but please show what you have
accomplished so far.

Frank
 
E

expvb

You posted your question to unrelated groups. Groups without "dotnet" or
"vsnet" in the name are for classic VB, VB6 and lower, which are
incompatible with dotnet. Please repost your question to "dotnet" groups
only.

Thank you
 
B

Bill McCarthy

dot nyet said:
On Mon, 9 Jun 2008 16:06:35 -0700 (PDT), (e-mail address removed) wrote:


First, you've confused tables and databases. If your database only
contains a single table then no harm (well sort of) but it sounds like
you want to serialize the data in a table or tables in your database.

I suggest you actually try reading what he wrote.

You could use Microsoft's XML methods but that would leave you dependent
on their proprietary code.


What a really silly statement, especially in a VB group.
More that likely it would be much simpler to
roll your own.

No it would be error prone and a waste of time, re-inventing the wheel.

Simply run your query and then output the values into a tab delimited
file.


Uh huh. Did you allow for unicode in that, non printing characters, and of
course encoding tab characters ?

This has the added advantage of being ready for insert using the
various Bulk Insert methods provided

As does XML.
but you can also of course roll
your own here as well.

Yeh on someone else's dime no doubt.
 
B

Bill McCarthy

Hi Ulli,

First, you've posted to a set of newsgroups that include VB6 newsgroups as
well as dotnet ones. I have set follow-up to just the dotnet newsgroup.

Second, have you tried the getting started videos on the VB web site:
http://msdn.microsoft.com/en-us/vbasic/bb466226.aspx
Look at the "Forms over Data Video series" and see if that helps get you
started.






Hello everybody,

I'd like to write code in order to find a specific record in a
database (*.mdf) connected to my VB Project and then have the
corresponding record being transferred to an array of string
variables. As the database consists of 11 columns (including the
primary key), and as I would like to let select a specific record by
its primary key, 10 string variables would be needed to capture the
entire database record.
By double clicking the *.xsd icon in the solution explorer, I opened
the dataset designer. After right clicking on the TableAdapter and
choosing the “TableAdapter Configuration Wizard”, I succeed to setup
a query with SQL statements (SELECT, FROM, WHERE statements), but I
didn’t arrive to write some working code to take advantage of this
query. Then I tried to use the SQL statements right in the VB code
itself, but wasn’t successful either. At the beginning I thought it
would be quite no big deal, but it turned out to be very tricky for
me.
Unfortunately, I didn’t find any useful solution at MSDN. Therefore I
would be very grateful for any advice how to write code so that a
specific database record will be copied to an array of string
variables.

Thanks in advance
Ulli
 
D

dot nyet

in <[email protected]>

Well, of course we'll have to defer to the Microsoft expert - Mr.
McBarfy. $DEITY McBarfy, you are absolutely brilliant. How could I
ever have missed that. BTW, have you been treating the sheep favorably
lately, because I'm hearing reports to the contrary.

STFU and crawl back under your rock lizard lips unless you have
something positive to add to the thread.

Frank
 
D

dot nyet

in said:
What a really silly statement, especially in a VB group.

Well, of course you could follow McBarfy's advice but you'd be taking
your chances there, I'd say. He's not awfully reliable and he's prone
to give answers that are skewed towards Microsoft's way of doing things.
Course if you're willing to take whatever they shove down your throat
then hey, McBarfy will be sure to show you the most appetizing way of
selling out to Microsoft leaving you with code that will take you years
to differentiate. But hey, that would be your call.

Frank
 
C

Cor Ligthert[MVP]

EXvb
..
You posted your question to unrelated groups. Groups without "dotnet" or
"vsnet" in the name are for classic VB, VB6 and lower, which are
incompatible with dotnet. Please repost your question to "dotnet" groups
only.

Based on?

Cor
 
C

Cor Ligthert[MVP]

Bill

As you should know there are no VB6 newsgroups.

You can tell that for VB with Net you are better of in the Net newsgroups,
but that does not mean that other VB newsgroup are only created for VB6.

Cor
 
D

dot nyet

On Tue, 10 Jun 2008 06:15:52 +0200, "Cor Ligthert[MVP]"
in said:
EXvb
.

Based on?

Cor

McBarfy's warped sense of Microsoftness, what else. C'mon Cor, it's
clear as a bell. Wake up and smell the coffee, will you?

Frank
 
C

Cor Ligthert[MVP]

Uli

As you mention the *.xsd which is a XML representation of a dataset I assume
that your message is meant for VB for Net.

It is always difficult to explain a problem while somebody is using the
designer, where you can use AdoNet however in VB9 is even probably Linq
easier for this problme.

In code in AdoNet it is like this

\\\
Dim conn as New OleDB.OleDBconnection(The connection string)
dim da as New OleDB.OleDBAdapter("Select theKey, Field1, Fieldetc from
YourDataBaseTable",conn)
dim dt as New DataTable
da.Fill(dt)
dim a(9) as string
for i as integer = 1 to dt.count-1
a(i-1) = dt.Rows(0).item(i)
next
///

This code works in all latest 3 versions of VB (7.1, 8 and 9) although you
should be aware of typos or whatever, I did use this message to write the
code and not an IDE.
(For version 7 it is however only slightly different and then that works as
well)

www.connectionstrings.com

Cor
 
C

Cor Ligthert[MVP]

Duh,

I saw at least this oneshould be
a(i-1) = dt.Rows(0).item(i).ToString

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top