473,383 Members | 1,919 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,383 software developers and data experts.

change field value in Datarow

cj
If I'm sitting on a datarow for a customer and want to change his phone
number only if it's blank what would I write?

if myDr("phone")= "" then
myDr("phone") = "mphone"
endif
mydr.acceptchanges()
Nov 14 '07 #1
6 5290
"cj" <cj@nospam.nospamschrieb
If I'm sitting on a datarow for a customer and want to change his
phone number only if it's blank what would I write?

if myDr("phone")= "" then
myDr("phone") = "mphone"
endif
mydr.acceptchanges()
First you should enable Option Strict and consider using typed datasets.
Yes, if you define "blank" being an empty string, this is possible. If you
mean a Null value, you can write if myDr("phone") is dbnull.value then
Acceptchanges should not be called because it resets the rowstate and
consecutive updates to the database won't be made.
Armin
Nov 14 '07 #2
"cj" <cj@nospam.nospamschrieb:
If I'm sitting on a datarow for a customer and want to change his phone
number only if it's blank what would I write?

if myDr("phone")= "" then

You may want to compare the value to 'DBNull.Value':

\\\
If MyDr("phone") Is DBNull.Value Then
...
End If
///

In addition, note that there is a 'IsDBNull' function available too.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://dotnet.mvps.org/dotnet/faqs/>
Nov 14 '07 #3
cj
ok but I was more concerned that mydr("phone") = mphone wasn't the
proper way to assign a variable to a field.

Armin, in regards to your comment about mydr.acceptchanges()
once I've changed a few records in the datatable I want these changes to
be reflected in the datasource. How do I accomplish that?

Herfried K. Wagner [MVP] wrote:
"cj" <cj@nospam.nospamschrieb:
>If I'm sitting on a datarow for a customer and want to change his
phone number only if it's blank what would I write?

if myDr("phone")= "" then


You may want to compare the value to 'DBNull.Value':

\\\
If MyDr("phone") Is DBNull.Value Then
...
End If
///

In addition, note that there is a 'IsDBNull' function available too.
Nov 14 '07 #4
Hi Cj,
once I've changed a few records in the datatable I want these changes to
be reflected in the datasource. How do I accomplish that?

Once you change a record in a DataTable, the changes are reflected in the
DataTable.

For example, we have a DataTable and retrieve data from a table in the
database and fill the data into the DataTable using SqlDataAdapter object.
All the rows in the DataTable have the RowState property of value Unchanged.

Then we make some changes to the first row in the DataTable and the changes
are there in the DataTable. But the value of the RowState property of the
first row becomes Modified.

You can call the GetChanges method on the DataTable to get a copy of the
DataTable containing all changes made to it and save the resulting
DataTable to the database. After you save the changes to the database
successfully, you can call the AcceptChanges method on the previous
DataTable to commit all the changes made to the table and then the value of
the RowState property of the first row becomes Unchanges again.

Hope I make some clarifications.
If you have any question, please feel free to let me know.

Sincerely,
Linda Liu
Microsoft Online Community Support

Nov 15 '07 #5
cj.

As far as I know does the dataadapter only update rows which have a rowstate
other then unchanged, so the benefit is not much, to collect them first by
checking first if it haschanges (only in a dataset) and then getchanges as
it is by instance Linda describes.

The dataadapter will with do automaticly the acceptchanges (set as changes
done to the database) if you use direct the table.

Cor
Nov 15 '07 #6
cj
thanks

Cor Ligthert [MVP] wrote:
cj.

As far as I know does the dataadapter only update rows which have a rowstate
other then unchanged, so the benefit is not much, to collect them first by
checking first if it haschanges (only in a dataset) and then getchanges as
it is by instance Linda describes.

The dataadapter will with do automaticly the acceptchanges (set as changes
done to the database) if you use direct the table.

Cor

Nov 15 '07 #7

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

Similar topics

2
by: Richard | last post by:
Hi, I have a DateTime picker control on a form. The datetime picker control is data bound to a column in a DataTable. Yes I know about bound DateTime pickers and DBNull and etc. so no troubles...
2
by: Amos | last post by:
I'm trying to display a field from a datarow like this: DataRow myRow = DS_Urb.Tables.Select("Code = 'MyCode'"); // it returns at least one row MessageBox.Show (myRow.ToString(), urb); But...
3
by: Miguel Dias Moura | last post by:
Hello, i know how to hide a table according to a condition: <table runat="server" visible='<%# dataSetBibliotecas.FieldValue("Titulo", Container) <> "" %>'... Now I am trying to change the...
6
by: timbobd | last post by:
I have a Windows form that displays a database table in a DataGrid. When you click on a row, the row's values get copied to bound TextBoxes below, and when the "Save" button is clicked the database...
2
by: simon | last post by:
hello, new to vb.net, have a few questions about DataGrid. I have a dataGrid that is working pulling a dataset back from a stored proc and binding to the datagrid for display the datagrid's...
3
by: Jim in Arizona | last post by:
I have a gridview that's being populated from an access db query. The problem I'm having is that the date/time fields in access that are populating the gridview are showing both date and time, when...
2
by: remya1000 | last post by:
i'm using VB.NET. and its a windows application. in my program i need to display a table in datagrid. so i created the table using DataTable and i'm calling that dataTable to dataGrid. and its...
1
by: Ben | last post by:
Hi, The gridview contains a radiobuttonlist with boolean values (true/false) coming from a database. In normal mode, the gridview displays True or False for that field. What i want is to...
10
by: Andy B | last post by:
If I have the following text in a dataset table column: "This agreement establishes that {BandName} will play on {EventDate} between {StartTime} and {EndTime}..." How would I then take the field...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
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: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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?

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.