Solved

vb.net sql

Posted on 2004-10-07
7
222 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 35 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
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.

 

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

Entering a date in Microsoft Access can be tricky. A typo can cause month and day to be shuffled, entering the day only causes an error, as does entering, say, day 31 in June. This article shows how an inputmask supported by code can help the user a…
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Progress
Introduction to Processes

623 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