How to save NULL in SQL DB using c# - save

I need to save just NULL in a column of SQL DB Table. but it is saving as 'NULL' or "" (blank). How to save just NULL?

There is a special object: DBNULL. You can handle this as null.

Related

TFDBatchMove trying to write NULL into a not Null Firebird DB column

I'm trying to use Delphi 11.2's TFDBatchMove to make a copy of a record in a Firebird database table. The table contains at least one column which is set to "not null" and a default value for the column is specified.
The reader for the TFDBatchMove is a TFDBatchMoveDataSetReader which gets a TFDQuery assigned to .DataSet. That query selects all the columns to copy, which excludes the "not null" column!
The Write for the TFDBatchMove is a TFDBatchMoveSQLWriter, which only gets the DBConnection assigned and the correct TableName.
At runtime I get an exception on .Execute of the TFDBatchMove:
First chance exception at $7720E292. Exception class EIBNativeException with message
'[FireDAC][Phys][FB]validation error for column "MEINE_TABELLE"."MEINE_SPALTE", value "*** null ***"'. Process MeineExe.exe (6728)
How to prevent it trying to write to that column?
I meanwhile found out that the writer has already some event assigned where I can modify the data written based on which column it tries to write to and there I can (and even need to) set a value for that not null colmum which differs from the default specified in the database anyway.
So one can either "close" this question as "resolved" or wonder why the TFDBatchMove seemingly tries to write null into that column, which was not in the select clause of the reader instead of letting the DB use the default value set up.

How to handle an autoincremented ID in HANA from a SAPUI5-application?

in my SAPUI5-Application I got the following function that takes the data and creates an entry in my HANA DB:
onCreateNewCustomer: function(){
var oEntry = {};
oEntry.NAME = this.byId("name").getValue();
oEntry.CITY = this.byId("city").getValue();
oEntry.PHONE = this.byId("phone").getValue();
oEntry.ID = this.byId("id").getValue();
// Post data to the server
this.getOwnerComponent().getModel("CustomerModel").create("/Customer", oEntry, null);
this.byId("createCustomer").close();
//location.reload();
}
The creating process works and my entries get saved. In the next step I wanted to implement my table in HANA in that way, that the ID of the entries will be autoincremented so the user does not have to enter it. I used the following command to create my table:
create column table TABLE
(ID bigint not null primary key generated by default as IDENTITY,
FIRSTNAME nvarchar(30))
That worked, table is created. The problem now is, if I use the code above without providing the ID, the following error is logged by the console:
The following problem occurred: HTTP request failed 400,Bad Request,The serialized resource has an missing value for member 'ID'.
The entry does not get saved in my DB. If I execute the following SQL-Statements in my HANA Workbench without providing the ID, it works:
insert into TABLE (FIRSTNAME) values (‘David’);
insert into TABLE (FIRSTNAME) values (‘Mike’);
insert into TABLE (FIRSTNAME) values (‘Bobby’);
So I did some searching on google but did not find a proper solution on how to do this. My goal is that the entry gets saved and the ID is provided by my HANA DB without providing it from my SAPUI5 Application.
Probably you are using ODataV2 XSODATA implementation which does not support auto-increment. The possible solution here is to use a database sequence and then with a separate request get a value from it and use it in OData create statement.
Did you try creating a new record by commenting out the below code like ?
oEntry.ID = this.byId("id").getValue();
With identity fields, if you provide the value you have to explicitly identify that you are providing the column value. Otherwise, just omit the columnn name and value from the INSERT command.

Grails getPeristentValue returning null for clearly existing values

I'm running into a situation where a record is returning null for getPersistentValue(name) even when I can verify that the value was NOT null.
Test:
//get it
def team =Team.get(params.id)
if(team){
log.debug(team.dateCreated);//logs date correctly
team.properties=params;
log.debug(team.getPersistentValue('dateCreated');//logs NULL???
}
It does not do this for all records. The only obvious difference I can find is the "version" column kept by grails, but manually messing with this didn't alter the behavior. What situations would cause this method to return null when the record exists and the value was set on it?

How update DB Value with NULL using Grails

I am trying to update the DB value to NULL using Properties, but the NULL values are not updated.
The following is the code snippet
def a = Docs.findById(1)
a.properties = b
b has the following values
[name:abc, level:null]
Data appears not to be saving into the DB. How can I save the data?

Passing value to database

does an empty text box pass an empty value to the database ** SQL server 2008** or an empty
string
i am using string.empty method before saving the data cause i need to clear the data
before the user inputs anything
i am not allowing nulls in my table but the passed value by the text box seems to be passed
as " " not as null so the table is accepting that value and I don't want that to happen
You could set the textbox value to null instead op String.Empty
It's also recommended to check the input before adding it to the database. Like so:
if (String.IsNullOrEmpty(txtTextbox.Text))
//No value

Resources