Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

vb.net sql

Posted on 2004-10-07
7
Medium Priority
?
224 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
The top UI technologies you need to be aware of

An important part of the job as a front-end developer is to stay up to date and in contact with new tools, trends and workflows. That’s why you cannot miss this upcoming webinar to explore the latest trends in UI technologies!

 

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …
Six Sigma Control Plans

664 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