Im coding a programm with VB.NET (2010), which works with a local database(.sdf - SQL Server CE).
Now, I need to execute two SELECT command. Here an example to understand what I want:
SQL command example 1:
SELECT A FROM tbl_Name
If I read this result with SqlCeDataReader, I will get following:
James
Tom
Mike
SQL command example 2:
SELECT B FROM tbl_Age
If I read this result with SqlCeDataReader, I will get following:
14
15
16
The problem is, how can I build a string which contains finally a value like this ->
James;14
Tom;15
Mike;16
How can I do that? I know that I have to use a StringBuilder and then AppendLine(), but the problem/question is more: How can I bring together the NAME and the AGE in one line? How can I solve this problem elegant? I hope you can help me. Thanks! BK_
Update:
No, they havent any relation. Im working with Sql Server CE.
Otherwhise it would be very nice, if there is a table update possible. That means, if I can update these both tables to one table like:
Tbl_personality Column Name and Column Age
And than read it at once with SQL * FROM tbl_personality
The question is how these tables are related, do you have a foreign-key in
table_age
that leads totbl_name
? Then you can use aJOIN
and a single query.You could fill a
List<User>
whereUser
is a custom class with both properties:Now use an
INNER JOIN
to link both tables on the FK and you get the correct age for every name:You can add instances of
User
in while you read all records:if you want to output all:
Edit: Here the VB.NET version: