473,385 Members | 1,983 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Field Concatenation in SQL Dataset for Combobox

I have read the threads on here about adding a calculated column to a dataset
to get the concatenation of first and last name fields into a single name
field and then binding the calculated field to the control on a form.

I am coming to VB.NET and ADO.NET and SQL Server from Visual Foxpro with its
embedded SQL. I'm used to being to combine fields on the fly inside my sql
statement.

Is it true that this can not be done using the above tools and in the above
scenario?
Must one always create caluclated fields by adding them to a dataset?

Please note.. I'm not arguing for or against VFP vs VB... I just want to
make sure I'm not missing an alternative that might exist that resembles the
VFP way.

Also.. while on the topic... I am having difficulty in getting the
calculated field's name to show up as a display member option for a combobox
control who's dropdown style is dropdown list.

I am using this code in the form's load event without error but without the
desired result:

Customers1.Clear()
Dim dc As DataColumn
dc = New DataColumn("Name")
dc.DataType = System.Type.GetType("System.String")
dc.Expression = "lname + ', ' + fname"
Customers1.Tables(0).Columns.Add(dc)
OleDbDataAdapter1.Fill(Customers1)

The code doesn't generate an error but the new datacolumn "Name" does not
show up in the display member field on the properties sheet for the control.

Before I tried using the calculated field, my code was this...

Customers1.Clear()
OleDbDataAdapter1.Fill(Customers1)

....and the display member showed the fields and I could bind them to the
control.

Please note I am able to see the calculated column when I preview the data
set.
Should my new code BE somewhere else rather than form load event?

If you have the time to comment, I'd appreciate it.

Nov 21 '05 #1
4 4700
Stewart,

It is not a strongly typed dataset so your fieldnames are from the fill, can
you try to do that direct after the

OleDbDataAdapter1.Fill(Customers1)
Dim dc As DataColumn
dc = New DataColumn("Name")
dc.DataType = System.Type.GetType("System.String")
dc.Expression = "lname + ', ' + fname"
Customers1.Tables(0).Columns.Add(dc)

I am not sure of that, it is just a try.

(I assume that lname and fname are exactly the columnnames case sensitive as
in your select or in your databasetable)

Cor
Nov 21 '05 #2
Hi Cor,

I tried moving the code as you suggested. It had no effect and I still can
not see 'Name' as a display member. Your assumption is correct. I respected
the spelling and case sensitivity of the field names exactly.

I appreciate your reply though. Let me know if you can suggest anything else.

I'm wondering if I should delete the adapter or/and dataset and recreate them.

Stewart

"Cor Ligthert [MVP]" wrote:
Stewart,

It is not a strongly typed dataset so your fieldnames are from the fill, can
you try to do that direct after the

OleDbDataAdapter1.Fill(Customers1)
Dim dc As DataColumn
dc = New DataColumn("Name")
dc.DataType = System.Type.GetType("System.String")
dc.Expression = "lname + ', ' + fname"
Customers1.Tables(0).Columns.Add(dc)

I am not sure of that, it is just a try.

(I assume that lname and fname are exactly the columnnames case sensitive as
in your select or in your databasetable)

Cor

Nov 21 '05 #3
Stewart,

I have created and added this sample to our website.

http://www.windowsformsdatagridhelp....c-f0b560f43e7c

I hope this helps,

Cor
Nov 21 '05 #4
Hi Cor,

I checked the tip and your site (nice by the way). It is clearly written
and I understand it but it does not address my problem directly. I think my
problem exists because I do not yet fully understand the ado.net
manipulations of datatables within datasets. I will continue my studies.

Thanks,

Stewart
"Cor Ligthert [MVP]" wrote:
Stewart,

I have created and added this sample to our website.

http://www.windowsformsdatagridhelp....c-f0b560f43e7c

I hope this helps,

Cor

Nov 21 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Marty | last post by:
Hi, Ok I use the OLEDBConnector and dataset to retrieve data from my Access DB. I have a problem to read/parse the dataset and I would like to know if I am using the right object to reach my...
2
by: Wishing I was skiing mom | last post by:
Newbie to VB .NET. My solution contains an item maintenance screen, one of the fields on the screen is an item status, this field is defined as a listbox. The listbox item property contains a...
1
by: | last post by:
Greets, I have a question I have combo box that gets a column in a dataset when I change the combo box the dataset changes and that works well. The problem is the fields on the from that...
6
by: chreo | last post by:
Sorry for weird title and sorry for my English (I'm from Poland). This is the problem: I have form with many controls. There are three comboboxes - each should have table STREETS as DataSource....
30
by: dbuchanan | last post by:
ComboBox databindng Problem == How the ComboBox is setup and used: My comboBox is populated by a lookup table. The ValueMember is the lookup table's Id and the DisplayMember is the text from a...
2
by: Simon Verona | last post by:
I have a combobox that is contained within a user control. Whilst the application is running, I'm attaching the combobox to a new dataset. The problem I'm getting is that the combobox doesn't...
2
by: Phil | last post by:
I need to created a typed dataset for a xml flat file and bind that dataset to a combobox. I was able to do this in VS.Net 2003 easy enough, but can't get it to work in VS.Net 2005. I've come...
10
by: AA Arens | last post by:
I have two tables, one consists of company info like name and phone number. Another table where I have to fill in the contact persons. Part of the form is to choose the company he works for (From...
4
by: cwilliams01 | last post by:
Hello I am new to VB.NET, so sorry if this is really obvious. I have written the following code to fill my dataset from a stored procedure requiring 1 paramter input (from a SQL database). The...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.