 |
| Visual Studio 2005 For discussing Visual Studio 2005. Please post code questions about a specific language (C#, VB, ASP.NET, etc) in the correct language forum instead. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the Visual Studio 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

January 10th, 2007, 09:59 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Table Adapter Query - Am i missing something?
Howdy all,
I'm completely new to VS2005 environment and it's ways and I need a little help with some of the basics.
I have a dataset with a table called Prospect_Details. Now I have a query that I've created called 'GetFullName' that simple says:
"SELECT Title, First_Name, Last_Name FROM Prospect_Details WHERE ID = ?"
So essentially I just want the query to return the full name of the prospect.
Now, on my form I have 2 textboxes. One is the ID Textbox whose value is bound to the ID column on the Prospect_Details table. When the form loads, I want to execute the above query and have it return the prospects full name according to the value in the ID Textbox. Sounds simple enough.
I've been using the following code to try and achieve this:
Dim TempName as string
TempName = Me.Prospect_DetailsTableAdapter.GetFullName(Me.IDT extBox.Text)
Me.TextBox1.Text = TempName
The problem is, the query seems to be only returning the first column value and not the full name, so instead of being "Mrs Jane Doe" it's simply returning "Mrs".
I have racked my brain trying to figure this out, and nothing I've done seems to work, so I thought it was time to put it out there in the world and admitt defeat. Most people will laugh at me which I'm fine with, my skills are with VBA so this is all very new to me and I'm just trying to expand my skills, so if anyone can help me out, I'd be greatly appreciative.
Cheers
In Distress.
|
|

January 10th, 2007, 10:35 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
The problem here is that you are return a dataset wtih three values in it. and trying to cast to a string.
I would have excpected an exception in this case but it seems to be defaulting to the first value avaiable from what you have said.
I see you have two options depending on what else you wish to do with the data set when you have the data.
OPT1:
Change your query to return only what you required.
SELECT (Title + ' ' + First_Name + ' ' + Last_Name) as Full_Name FROM....
but you still should explicitly ask for the field you want
TempName = Me.Prospect_DetailsTableAdapter.GetFullName(Me.IDT extBox.Text).Tables[0][Full_Name];
OPT2:
build the output from the dataset.
Dataset ds = Me.Prospect_DetailsTableAdapter.GetFullName(Me.IDT extBox.Text);
TempName = ds.Tables[0][Title] + " " + ds.Tables[0][First_Name] + " " + ds.Tables[0][Last_Name].....
This is the best option in my opintion, as you will no doubt have other uses for the fields seperately in an editing sence and there is no need to have two data adapters
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

January 10th, 2007, 10:37 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Woops, sorry these fields names are passed as strings ds.Tables[0]["First_Name"], not[First_Name]
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

January 10th, 2007, 10:44 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
Oi Oi Oi
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

January 10th, 2007, 11:02 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Champion. Thanks for that. I used the suggest ammendment to the query. One thing I wanted to ask though was about your suggested option. You used 'Dataset ds', but when I tried using this I obviously got a syntax prob. Should is be 'Datasetds' or is there a piece of the puzzle that I'm missing....
|
|

January 10th, 2007, 11:32 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 596
Thanks: 1
Thanked 3 Times in 3 Posts
|
|
The missing link is my inability to type.
DataSet with capital S.
I didn't build this code so you will have to check all the syntax.
TIP: I use intellisence heaps in VS.NET, type 'Data',(without '), in your page and then press CTRL&Space and you will see any object thats name starts with Data that can be seen by your code.
Intellisence is a great learning tool as well as a time saver.
Carn the mighty Freo Dockers!
======================================
They say, best men are molded out of faults,
And, for the most, become much more the better
For being a little bad.
======================================
|
|

January 11th, 2007, 05:55 PM
|
|
Registered User
|
|
Join Date: Jan 2007
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Excellent. Works a treat. Thanx for taking the time to help out a newbie.
|
|
 |