Solved

vb.net sql

Posted on 2004-10-07
7
214 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 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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now