Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

vb.net sql

Posted on 2004-10-07
7
Medium Priority
?
226 Views
Last Modified: 2010-04-17
I am using this code

   
        cmd.Connection = con
        cmd.CommandText = "SELECT NAME FROM table1 group by NAME "
        datareader = cmd.ExecuteReader(CommandBehavior.SingleResult)

        Do While datareader .Read = True
            combobox1.Items.Add(datareader .GetString(0))
        Loop

the combobox populates with the data from that database the problem is the group by isn't working. Does it work in vb.net. I need to eliminate the same names. This table has a person name in it more then once I just need it to be in the combobox once not every entry. What do I do?


0
Comment
Question by:hogan9111
  • 4
  • 2
7 Comments
 
LVL 1

Accepted Solution

by:
mrloumrlou earned 140 total points
ID: 12249898
try "SELECT DISTINCT NAME FROM TABLE1"
0
 

Author Comment

by:hogan9111
ID: 12250151
didn't work
0
 
LVL 1

Expert Comment

by:mrloumrlou
ID: 12250600
How many names are there?  Are just a couple names not merging?  If so, they may have a space after them.  Try the same thing but trim it:
"SELECT DISTINCT LTRIM(RTRIM(NAME)) FROM TABLE1"

That has to be it because DISTINCT will not bring back duplicates.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 

Author Comment

by:hogan9111
ID: 12252900
u were right I had a space after the 1.

Hey real quick I am trying to tie to tables together a 1 to many relationship and I am having problems in vb.net getting it to work.

How do you link to tables

this is what I have as far as tables

table1
name = primary key
date
age

table2
id = primary key autonumber
name
grade
location

what is the proper way to link the two tables. I would like to do so because if I decide to delete a certain name I want it to take it out of both tables, not just 1.



Any ideas

0
 
LVL 2

Expert Comment

by:UncleMidriff
ID: 12254227
You probably already know this, but I would advise using something other than "name" as a primary key in table1.  It is not all that uncommon of an occurence for two people in the same database to have the same first and last name.  If you already knew that, just ignore me :)

Here's how I would set up the two tables:

Table1
PersonID
Name
Date
Age

Table2
GradeID
PersonID
Grade
Location

Then if you want to delete a person from both of these tables, you'll have to go and delete every record in Table2 that has that person's PersonID value in the PersonID field.  Once you've done that, you can delete the person from Table1.

If I completely misunderstood your question, please forgive me.  It's getting late and close to time for me to go home.

Good luck.
0
 

Author Comment

by:hogan9111
ID: 12259584
what sql statement would I use to pull the two tables together for viewing, updating, etc
0
 

Author Comment

by:hogan9111
ID: 12262794
you there?????
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Make the most of your online learning experience.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
Starting up a Project

916 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question