473,385 Members | 1,838 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.

Inserting empty values into NOT NULL columns via ODBC

We are writing a C application that is using ODBC to insert records
into a database. We have a NOT NULL column that can legitimately have
an empty value, i.e. we know the value and it is empty (i.e. a zero
length string).

We are using SQLBindParameter() to bind a variable to the
parameterized insert statement <<in the form: INSERT INTO table VALUES
(?, ?, ?)>>. We are using SQLExecDirect() to process the SQL.

We are running into the problem where ODBC is converts the empty (zero
length) string into a NULL value and this errors due to the fact that
the column is defined as NOT NULL.

We do not want to redefine the column as NULL, becasue my
understanding of the correct usage of a NULL column is to indicate
that a value is unknown or meaningless... in our case we know the
value (it is empty) and an empty value has meaning within our
application.

I'm sure that this issue has been seen and address thousands
(millions?) of times... any guidance would be appreciated.
Jul 20 '05 #1
2 8763
NULL means that at the time the row is created that no data has to be
inserted, into that column and will not be checked for.
NOT NULL means there will be a check to make sure there is something other
than a null.
The best you can do is use a space for varchar and 0 or 0.0 for numeric.

"FizzBin" <id*********@yahoo.com> wrote in message
news:64**************************@posting.google.c om...
We are writing a C application that is using ODBC to insert records
into a database. We have a NOT NULL column that can legitimately have
an empty value, i.e. we know the value and it is empty (i.e. a zero
length string).

We are using SQLBindParameter() to bind a variable to the
parameterized insert statement <<in the form: INSERT INTO table VALUES
(?, ?, ?)>>. We are using SQLExecDirect() to process the SQL.

We are running into the problem where ODBC is converts the empty (zero
length) string into a NULL value and this errors due to the fact that
the column is defined as NOT NULL.

We do not want to redefine the column as NULL, becasue my
understanding of the correct usage of a NULL column is to indicate
that a value is unknown or meaningless... in our case we know the
value (it is empty) and an empty value has meaning within our
application.

I'm sure that this issue has been seen and address thousands
(millions?) of times... any guidance would be appreciated.

Jul 20 '05 #2
FizzBin (id*********@yahoo.com) writes:
We are writing a C application that is using ODBC to insert records
into a database. We have a NOT NULL column that can legitimately have
an empty value, i.e. we know the value and it is empty (i.e. a zero
length string).

We are using SQLBindParameter() to bind a variable to the
parameterized insert statement <<in the form: INSERT INTO table VALUES
(?, ?, ?)>>. We are using SQLExecDirect() to process the SQL.

We are running into the problem where ODBC is converts the empty (zero
length) string into a NULL value and this errors due to the fact that
the column is defined as NOT NULL.
...

I'm sure that this issue has been seen and address thousands
(millions?) of times... any guidance would be appreciated.


Nah, direct programming against the ODBC interface from C is not what
everyone does. :-)

It would probably help if you posted your code, both the call to
SQLBindParameter and SQLExecDirect. If you make a complete program
of it, I might even be able to play with. (OK, so I have never programmed
against the ODBC interface myself.)

--
Erland Sommarskog, SQL Server MVP, so****@algonet.se

Books Online for SQL Server SP3 at
http://www.microsoft.com/sql/techinf...2000/books.asp
Jul 20 '05 #3

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

Similar topics

1
by: Wayno | last post by:
My php logs are coming up empty. I have done all I can think of, and all that made sense to me. Can someone take a look at my php.ini please and tell me what you think may be the problem. I...
3
by: tornado | last post by:
Hi all, I am pretty new to PHP. I was reading PHP manual and trying out the example from 2nd chapter (A simple Tutorial). When i try to print the variable as given in the example it returns...
0
by: GreenFROG Design | last post by:
Data Processing and SQL INSERTING Hello guy's i'm faced with a horrible dilemma i have whole dictionary that i have to enter into a database. I have all the text and i would like to convert it...
0
by: Marko Poutiainen | last post by:
Situation: We had to make our SQLServer 2000 database multi-lingual. That is, certain things (such as product names) in the database should be shown in the language the user is using (Finnish,...
16
by: bill | last post by:
How can I insert a record with a null value in one of the fields? I need to use the update method from a data adapter. The data is in a XML file.
2
by: Andreas Palm | last post by:
I have a dataset that has DBNull in certain columns, now when I write out this one to XML, I only get the columns as elements that do have data in it. However I do need also the empty colums as...
9
by: Andrew Banks | last post by:
I'm running the following code in a C#.NET page and it doesn't enter the values into the DB. I'm certain the problem is to do with the txtBirth field. It allows users to enter a DOB as dd/mm/yyyy...
7
by: Dabbler | last post by:
I'm using an ObjectDataSource with a stored procedure and am getting the following error when trying to update (ExecuteNonQuery): System.Data.SqlClient.SqlException: Procedure or Function...
3
by: rcoco | last post by:
Hi, I want to share this problem. I have a datagrid that will help me Insert data into sql database. So I made a button On my form so that when I press the button a new row on datagrid should be...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
0
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...
0
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,...

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.