Solved

vb.net sql

Posted on 2004-10-07
7
216 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 

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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
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 …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

786 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