Hi, I'm trying to update a DBF file which I'm using VB.NET ODBC adapters,
commands and connections. I fill the dataset and databind the columns to
textboxes on my form. I can successfully view, delete and update the
records. The problem is when I try to add a new record.
Because I actually have a few controls bound to the same table I use
FORM.BINDINGCON TEXT to keep it all synced. So, using the
form.bindingcon text.addnew method. my textboxes clear and I enter 2 or 3 of
the 7 fields. When I hit my save button which does a
BindingContext. EndCurrentEdit and creates a new dataset (dsChanged) with
only the "changed" records, then I do a dataAdapter.Upd ate(dsChanged) and it
throws an exception stating something about my first unentered field is
DBNull. and the database does not allow that. If I actually fill in the
field that I got the error on and try again, the error "moves" to the next
unentered field.
I've tried a couple of ways programatically "blank out" the fields in the
dsChanged dataset, but they remain (the debugger quickview confirms this) a
DBNull value.
How can I eliminate the DBNull values from my dataset programatically ? Any
suggestions gratefully accepted. 4 3214
The problem is not your code... it is a disconnect between your code and the
expectations of your database.
If you expect to be able to enter two of the seven fields and save the
record, then the other five fields must allow null values in the database.
If the other five fields do not allow nulls, you have to ask yourself: did
the database developer (was it you?) set up the column nullability correctly
on those columns.
In other words, the right answer may be to fix the database, and not your
code.
--
--- Nick Malik [Microsoft]
MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not
representative of my employer.
I do not answer questions on behalf of my employer. I'm just a
programmer helping programmers.
--
"JohnR" <Jo******@hotma il.com> wrote in message
news:0a1%d.9992 $Ue6.7916@trndn y04... Hi, I'm trying to update a DBF file which I'm using VB.NET ODBC adapters, commands and connections. I fill the dataset and databind the columns to textboxes on my form. I can successfully view, delete and update the records. The problem is when I try to add a new record.
Because I actually have a few controls bound to the same table I use FORM.BINDINGCON TEXT to keep it all synced. So, using the form.bindingcon text.addnew method. my textboxes clear and I enter 2 or 3 of the 7 fields. When I hit my save button which does a BindingContext. EndCurrentEdit and creates a new dataset (dsChanged) with only the "changed" records, then I do a dataAdapter.Upd ate(dsChanged) and it throws an exception stating something about my first unentered field is DBNull. and the database does not allow that. If I actually fill in the field that I got the error on and try again, the error "moves" to the next unentered field.
I've tried a couple of ways programatically "blank out" the fields in the dsChanged dataset, but they remain (the debugger quickview confirms this) a DBNull value.
How can I eliminate the DBNull values from my dataset programatically ? Any suggestions gratefully accepted.
Hi Nick,
You have a very good point, and I will check it out. However the DB I'm
using now is just a test for when I convert an old VB6 application to VB.NET
and I wanted to make sure I understood how to do all the things I need to do
for the conversion.
The actual production DB may, in fact, not allow null values, so my
question is this: After I load the dsChanged dataset with the newly
inserted row, I try to replace any nulls with a blank string: here's a code
snippet:
dsChanged = dsTele.GetChang es() 'get all the changed rows and stick them in
a dataset
If Not dsChanged Is Nothing Then
For Each xRow As DataRow In dsChanged.Table s("rolodex").Ro ws
If Not xRow.RowState = DataRowState.De leted Then 'can't change field on del
rec
'scan remaining columns to ck for null entries
For i As Int32 = 0 To xRow.ItemArray. GetLength(0) - 1
xRow.ItemArray( i) = utility.NullSaf eString(xRow.It emArray(i), " ")
Next
End If
Next
End If
The nullsavestring will stick the 2nd parameter (the " ") into the 1st
parameter (xRow.ItemArray (i) ) if it is null.
Do you see anything wrong with this code? Cause it doesn't seem to work,
even though when I trace it thru debug it seems like it should work.
Thanks, John
"Nick Malik [Microsoft]" <ni*******@hotm ail.nospam.com> wrote in message
news:yr******** ************@co mcast.com... The problem is not your code... it is a disconnect between your code and the expectations of your database.
If you expect to be able to enter two of the seven fields and save the record, then the other five fields must allow null values in the database. If the other five fields do not allow nulls, you have to ask yourself: did the database developer (was it you?) set up the column nullability correctly on those columns.
In other words, the right answer may be to fix the database, and not your code.
-- --- Nick Malik [Microsoft] MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not representative of my employer. I do not answer questions on behalf of my employer. I'm just a programmer helping programmers. -- "JohnR" <Jo******@hotma il.com> wrote in message news:0a1%d.9992 $Ue6.7916@trndn y04... Hi, I'm trying to update a DBF file which I'm using VB.NET ODBC adapters, commands and connections. I fill the dataset and databind the columns to textboxes on my form. I can successfully view, delete and update the records. The problem is when I try to add a new record.
Because I actually have a few controls bound to the same table I use FORM.BINDINGCON TEXT to keep it all synced. So, using the form.bindingcon text.addnew method. my textboxes clear and I enter 2 or 3 of the 7 fields. When I hit my save button which does a BindingContext. EndCurrentEdit and creates a new dataset (dsChanged) with only the "changed" records, then I do a dataAdapter.Upd ate(dsChanged) and it throws an exception stating something about my first unentered field is DBNull. and the database does not allow that. If I actually fill in the field that I got the error on and try again, the error "moves" to the next unentered field.
I've tried a couple of ways programatically "blank out" the fields in the dsChanged dataset, but they remain (the debugger quickview confirms this) a DBNull value.
How can I eliminate the DBNull values from my dataset programatically ? Any suggestions gratefully accepted.
Hi All,
Well, I found the answer to my own problem.... The line:
xRow.ItemArray( i) = utility.NullSaf eString(xRow.It emArray(i), " ")
was not updating the columns in the dataset as expected. when I changed the
ItemArray to Item like this:
xRow.Item(i) = utility.NullSaf eString(xRow.It em(i), " ")
it worked fine. Now I have to go back and study the difference between
using Item and ItemArray.
John
"JohnR" <Jo******@hotma il.com> wrote in message
news:8Tl%d.1205 4$I16.11095@trn dny03... Hi Nick,
You have a very good point, and I will check it out. However the DB I'm using now is just a test for when I convert an old VB6 application to VB.NET and I wanted to make sure I understood how to do all the things I need to do for the conversion.
The actual production DB may, in fact, not allow null values, so my question is this: After I load the dsChanged dataset with the newly inserted row, I try to replace any nulls with a blank string: here's a code snippet:
dsChanged = dsTele.GetChang es() 'get all the changed rows and stick them in a dataset
If Not dsChanged Is Nothing Then
For Each xRow As DataRow In dsChanged.Table s("rolodex").Ro ws
If Not xRow.RowState = DataRowState.De leted Then 'can't change field on del rec
'scan remaining columns to ck for null entries
For i As Int32 = 0 To xRow.ItemArray. GetLength(0) - 1
xRow.ItemArray( i) = utility.NullSaf eString(xRow.It emArray(i), " ")
Next
End If
Next
End If
The nullsavestring will stick the 2nd parameter (the " ") into the 1st parameter (xRow.ItemArray (i) ) if it is null.
Do you see anything wrong with this code? Cause it doesn't seem to work, even though when I trace it thru debug it seems like it should work.
Thanks, John
"Nick Malik [Microsoft]" <ni*******@hotm ail.nospam.com> wrote in message news:yr******** ************@co mcast.com... The problem is not your code... it is a disconnect between your code and the expectations of your database.
If you expect to be able to enter two of the seven fields and save the record, then the other five fields must allow null values in the database. If the other five fields do not allow nulls, you have to ask yourself: did the database developer (was it you?) set up the column nullability correctly on those columns.
In other words, the right answer may be to fix the database, and not your code.
-- --- Nick Malik [Microsoft] MCSD, CFPS, Certified Scrummaster http://blogs.msdn.com/nickmalik
Disclaimer: Opinions expressed in this forum are my own, and not representative of my employer. I do not answer questions on behalf of my employer. I'm just a programmer helping programmers. -- "JohnR" <Jo******@hotma il.com> wrote in message news:0a1%d.9992 $Ue6.7916@trndn y04... Hi, I'm trying to update a DBF file which I'm using VB.NET ODBC adapters, commands and connections. I fill the dataset and databind the columns to textboxes on my form. I can successfully view, delete and update the records. The problem is when I try to add a new record.
Because I actually have a few controls bound to the same table I use FORM.BINDINGCON TEXT to keep it all synced. So, using the form.bindingcon text.addnew method. my textboxes clear and I enter 2 or 3 of the 7 fields. When I hit my save button which does a BindingContext. EndCurrentEdit and creates a new dataset (dsChanged) with only the "changed" records, then I do a dataAdapter.Upd ate(dsChanged) and it throws an exception stating something about my first unentered field is DBNull. and the database does not allow that. If I actually fill in the field that I got the error on and try again, the error "moves" to the next unentered field.
I've tried a couple of ways programatically "blank out" the fields in the dsChanged dataset, but they remain (the debugger quickview confirms this) a DBNull value.
How can I eliminate the DBNull values from my dataset programatically ? Any suggestions gratefully accepted.
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Arek |
last post by:
Hey,
I am inserting values in the table:
Dim sqlcomm1 As SqlCommand = New SqlCommand("INSERT INTO tblTasks
(idTask, outdate) VALUES ('" & IDTask.text & "','" & txtOutdate.Text &
"')", conn)
sqlcomm1.ExecuteNonQuery()
Query is working fine if there is value in the txtOutDate, but if user
leaves the field txtOutdate empty, system insert date 1900-01-01. I want
|
by: chambersdon |
last post by:
I have an application that needs to insert nulls into the database and
I don't seem to be able to do this.
I am currently trying to do this with a Typed DataSet but I can't seem
to Insert Nulls (or udpate columns with a null value).
I have a column in a test table called 'anInteger'.
The Typed DataSet for this element has minOccurs="0" and the type =
xs:int.
To set this field to null I call the SetanIntegerNull method of my
typed...
|
by: JohnR |
last post by:
Hi, I'm trying to update a DBF file which I'm using VB.NET ODBC adapters,
commands and connections. I fill the dataset and databind the columns to
textboxes on my form. I can successfully view, delete and update the
records. The problem is when I try to add a new record.
Because I actually have a few controls bound to the same table I use
FORM.BINDINGCONTEXT to keep it all synced. So, using the
form.bindingcontext.addnew method. my...
|
by: Dylan Parry |
last post by:
Hi folks,
This is really confusing me. I am trying to insert a row into a
database, and then use scope_identity() to return the value of the ID
column for the record I have just created. The code I am using is
something like the below:
--- Start ---
// Build query
this.command = this.connection.CreateCommand();
|
by: Ryan |
last post by:
I have 2 Access '97 databases. I am trying to migrate all the data from one
to the other (append to existing records). I do not have Access '97 and
opening with Access XP or later causes problems. I have found I can connect
to the databases in Visual Studio 2005 and insert records, etc, so I'm
trying to write my code using VB 2005.
I have 2 connections, 2 datasets... OldDS and NewDS. First I populate both
datasets:...
| |
by: Martin Arvidsson |
last post by:
Hi!
I have two computed datafields that i am displaying in my windowsform.
When i try to update the dataset and commit the transaction.
I get an error message telling me that i cant update calculated fields. That
i can understand
but how to tell the dataset or what ever to NOT do this update to the
server?
|
by: Martin Z |
last post by:
INSERT INTO dbo.Transmission
(TransmissionDate, TransmissionDirection,
Filename, TransmittedData)
VALUES
(@TransmissionDate,@TransmissionDirection,@Filename,@TransmittedData);
SELECT @retVal = SCOPE_IDENTITY();
Pretty simple. There is an additional TransmissionID column that is
an autonumber and primary key. @retVal is always null in my table
adapter function, where I'm setting @retval (in the Parameters
|
by: Finn Stampe Mikkelsen |
last post by:
Hi
I have defined a table in my database, with 2 date-fields. I have set a
default value to DBNull. I have integrated a nullable datetimepicker control
to my project and set the apropriate NullValue in my datagridview...
Everything works great, with a table-row added manually to the database,
without setting any value to the second date-field. Both the datagridview
and the datetimepicker displays correctly the DBNull value..
|
by: cday119 |
last post by:
Can someone help me out with this one. I am trying to insert a row of data into an access database. The primary key is set to auto increment. It will work once but the next time you try an insert it says. "The changes you requested to the table were not successful because they would create duplicate values in the index, primary key, or relationship. " This error occurs on the daComputers.Update(dsHardware, "Computers") line
Here is the...
|
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...
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |