473,491 Members | 1,885 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Insert Null Value

RN1
How do I insert NULL values in a SQL Server DB table in a column whose
datatype is int? This is what I am trying currently (in the
UpdateCommand event function of a DataGrid):

----------------------------
Dim strSQL As String
Dim objErrorPercentage As Object

If (CType(ea.Item.Cells(8).Controls(0), TextBox).Text = "") Then
objErrorPercentage = DBNull.Value
Else
objErrorPercentage = CType(ea.Item.Cells(8).Controls(0),
TextBox).Text
End If

strSQL = "UPDATE Table1 SET.......ErrorPerc = " & objErrorPercentage &
".....WHERE....."
----------------------------

But the above generates the "Incoorrect syntax" error if the TextBox
is empty.
Oct 12 '08 #1
2 1660
On Oct 12, 2:28*pm, RN1 <r...@rediffmail.comwrote:
How do I insert NULL values in a SQL Server DB table in a column whose
datatype is int? This is what I am trying currently (in the
UpdateCommand event function of a DataGrid):

----------------------------
Dim strSQL As String
Dim objErrorPercentage As Object

If (CType(ea.Item.Cells(8).Controls(0), TextBox).Text = "") Then
* * objErrorPercentage = DBNull.Value
Else
* * objErrorPercentage = CType(ea.Item.Cells(8).Controls(0),
TextBox).Text
End If

strSQL = "UPDATE Table1 SET.......ErrorPerc = " & objErrorPercentage &
".....WHERE....."
----------------------------

But the above generates the "Incoorrect syntax" error if the TextBox
is empty.
1. Be careful with the sql injections.

2. If (CType(ea.Item.Cells(8).Controls(0), TextBox).Text = "") Then
objErrorPercentage = "NULL"
Oct 12 '08 #2
RN1 wrote:
How do I insert NULL values in a SQL Server DB table in a column whose
datatype is int? This is what I am trying currently (in the
UpdateCommand event function of a DataGrid):

----------------------------
Dim strSQL As String
Dim objErrorPercentage As Object

If (CType(ea.Item.Cells(8).Controls(0), TextBox).Text = "") Then
objErrorPercentage = DBNull.Value
Else
objErrorPercentage = CType(ea.Item.Cells(8).Controls(0),
TextBox).Text
End If

strSQL = "UPDATE Table1 SET.......ErrorPerc = " & objErrorPercentage &
".....WHERE....."
----------------------------

But the above generates the "Incoorrect syntax" error if the TextBox
is empty.
1) See Alexey's response
2) Use parameters instead of string concatenation:
strSQL = "UPDATE Table1 SET.......ErrorPerc =
@ParamErrorPerc.....WHERE....."
and
myCommand.Parameters.AddValue("ParamErrorPerc", objErrorPercentage)

--

Riki
Oct 12 '08 #3

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

Similar topics

2
23051
by: schumacker | last post by:
Hi everyone! I am working with Delphi v7 and MS SQLServer. I am trying to insert data in a table with a SQL sentence. Some of the fields of my table are type char or varchar, and they can have...
14
4268
by: serge | last post by:
I have a scenario where two tables are in a One-to-Many relationship and I need to move the data from the Many table to the One table so that it becomes a One-to-One relationship. I need to...
10
52380
by: Python_it | last post by:
Python 2.4 MySQL-python.exe-1.2.0.win32-py2.4.zip How can I insert a NULL value in a table (MySQL-database). I can't set a var to NULL? Or is there a other possibility? My var must be variable...
7
1932
by: trint | last post by:
This: string strSQL2 = "INSERT INTO tblTravelDetailMember(memberId, " + " TravelDetailUplineId, " + " rankId, " + " TravelDetailId, " + " CreatedDateTime, " + " Operator) " + "VALUES ('" +...
6
16242
by: FatboyCanteen | last post by:
When I using dataset to append a null value to the datetime field. It throw a error -> can not convert db.null to system.date Can there is any standard to pass a Null value to the DateTime...
8
13919
by: Martin Z | last post by:
INSERT INTO dbo.Transmission (TransmissionDate, TransmissionDirection, Filename, TransmittedData) VALUES (@TransmissionDate,@TransmissionDirection,@Filename,@TransmittedData); SELECT @retVal =...
0
2134
ak1dnar
by: ak1dnar | last post by:
There is a Error getting while i am entering records using this jsp file. <%@ page contentType="text/html; charset=iso-8859-1" language="java" import="java.sql.*" errorPage="" %> <%@ include...
1
2270
by: veasnamuch | last post by:
I have a problem while I create a trigger to my table. My objective is getting any change made to my table and record it in to another table . My have thousands records before I add new trigger to...
5
3437
by: =?Utf-8?B?bXBhaW5l?= | last post by:
Hello, I am completely lost as to why I can't update a DropDownList inside a DetailsView after I perform an insert into an object datasource. I tried to simply it down to the core demostration:...
2
5017
by: wizardry | last post by:
hello - i'm trying to insert a blob into my table, it will insert but the string that i insert when i query the inserted data returns null with 0 bytes in the column. I have other tables set...
0
7118
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,...
0
6980
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
7157
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,...
0
7192
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...
0
7364
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4886
isladogs
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...
0
3087
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...
0
3078
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1397
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.