Update Joined field in dataset (SELECT FirstName & ' ' & LastName AS Name ...)

  • Thread starter Thread starter Raymond
  • Start date Start date
R

Raymond

I have a dataset with one table with two fields (LastName
and Firstname). With SQL I "create" one more field:
SELECT FirstName & ' ' & LastName AS Name FROM Names;
Now i have 3 fields in my datatable.

The problem is when I update the dataset, the field Name
doesn't update. How I can update my Dataset so Name will
update to.

I use OleDbDataAdapter and OleDbCommandBuilder to update
my data.

I need this to use a combobox for select items in the
table Names.

/Raymond
 
In this instance, Name is NOT a field in the database so it would not be updated, Only Firstname and Lastname. You would need to parse the firstname and lastname out tof the
Name field and put them into their fields to update back to the database. The Name field created by the AS is not an updateable field.

Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.

Get Secure!
http://www.microsoft.com/security
http://www.microsoft.com/protect


--------------------
 
I cannot update the field, I thought so. But is there any
way to recreate the field Name with the new values after
I update the dataset. All I want is the combobox to
update with the new values.


/Raymond
-----Original Message-----
In this instance, Name is NOT a field in the database so
it would not be updated, Only Firstname and Lastname. You
would need to parse the firstname and lastname out tof
the
Name field and put them into their fields to update back
to the database. The Name field created by the AS is not
an updateable field.
 
Let me see if I have this clear Ok...So what you want basically is that when the values of the firstname and Lastname change you want the value of the NameField to change with
them correct? Something like
First Last Name
Scott Rose Scott Rose
would change to
First Last Name
Scot Rose Scot Rose

when the data was updated...

Now I guess my next question is then, Do you mean Updated back to the DataBase (In which case merely requery the database and rebind the Combo) or if it is just changed in
the DataSet?

If just changed in the dataset then you could set up an expression column that concatenates the values whenever they change. The sample code below, retrieves two fields from
teh Northwind database then adds and Expression Column to the DataSet that concatenates teh values in the fields (I used a datagrid so you could change the Firstname or Last
name values and see them change in the third field)


Dim con As New System.Data.SqlClient.SqlConnection("server=MyServer;uid=sa;pwd=Password;database=northwind")
Dim daCust As New System.Data.SqlClient.SqlDataAdapter("Select FirstName,LastName From employees", con)
Dim ds As New DataSet
daCust.Fill(ds, "Cust")
ds.Tables("Cust").Columns.Add("Name", Type.GetType("System.String"), "Firstname + ' ' + LastName")
DataGrid1.DataSource = ds
DataGrid1.DataMember = "Cust"


Scot Rose, MCSD
Microsoft Visual Basic Developer Support
Email : (e-mail address removed) <Remove word online. from address>

This posting is provided “AS IS”, with no warranties, and confers no rights.

Get Secure!
http://www.microsoft.com/security
http://www.microsoft.com/protect


--------------------
 
Back
Top