473,656 Members | 2,793 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.acceptchan ges()
Nov 14 '07 #1
6 5376
"cj" <cj@nospam.nosp amschrieb
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.acceptchan ges()
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.nosp amschrieb:
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.acceptchan ges()
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.nosp amschrieb:
>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
3861
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 with that stuff... However, as somebody out there probably knows, programmatically setting the DateTimePicker.Value property to a new VALUE does NOT in itself constitute a CHANGE to
2
11129
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 I get "System.Data.DataRow". How can I display field "Name" ?
3
1831
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 image file as follows: - Show the image "yes.gif" if the value of a dynamic field is equal to "YES"; - Show the image "no.gif" if the value of a dynamic field is equal to "NO".
6
11276
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 is updated (as is the DataGrid row) with changed values in the TextBoxes. Here are some observations: 1) When changes are typed into a text box and "Save" is clicked, the changes are reflected in the DataSet.Tables().Rows().ItemArray value, but...
2
12584
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 first column is a textbox(TemplateColumn), the other 3 columns are just display(BoundColumn). (1) if the value of the textbox is 0, then i'd like to change it null, so the box is empty
3
3291
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 the field should only be showing one or the other (date or time). Even on the back end of the database where the column properties are, I have chosen the smallest date/time formats. When the aspx page runs, it shows the date and time (ie:in a...
2
3832
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 working fine... but according to one of the field in that table i need to change the back color of that row. one of the field in that table called "Active", it will have value as True or False. so if Active =True then i need that corresponding row...
1
1978
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 change True' and 'False' by 'Yes' and 'No' in normal mode. I tried this, but still get True / False. Thanks for help
10
1218
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 names {BandName}, {StartTime}, {EndTime} and {EventDate}, match them up with actual dataset table column names, and show the actual values instead of the placeholders on the final page output? I know this would probably require some string parsing...
0
8382
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8297
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8816
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8717
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7311
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5629
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4300
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1930
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.