I have a sql query that is doing an update of records, how can I add NULL to
the field in the database if the field on my screen is blank?
example:
I have 5 textboxes, and a user can leave some blank, delete data from a text
box then hit update, how can I have NULL inserted into the field on the
database instead of having a blank record in the db 17 2345
NuB,
The simplest way is to not include that parameter at all unless it has data
in it.
So if you're adding parameters to your insert statement (using a sql command
object) it would look like this:
If MiddleNameTextB ox.Text.Trim.Le ngth > 0 Then
SqlCommand1.Par ameters.Add("@M iddleName", SqlDbType.NvarC har, 50).Value
= MiddleNameTextB ox.Text.Trim
End If
If a field in the sql database is nullable then not setting the parameter
will leave it null.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"NuB" <Nu*@discussion s.microsoft.com > wrote in message
news:95******** *************** ***********@mic rosoft.com... I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
cmd.Parameters. Add("@Blah", SqlDbType.Strin g, 128).Value = (firstName ==
null || firstName.Lengt h == 0) ? DBNull.Value : firstName;
You can do it cleaner in 2.0
cmd.Parameters. Add(....).Value = (string.IsNullO rEmpty(firstNam e) ??
DBNull.Value;
karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"NuB" <Nu*@discussion s.microsoft.com > wrote in message
news:95******** *************** ***********@mic rosoft.com... I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
And if ur using VB, you'll simply need to if/else
dim databaseFirstNa me as object
if firstName is nothing OrElse firstName.Lengt h = 0 then
databaseFirstNa me = DBNull.Value
else if
databaseFirstNa me = firstName
end if
Karl
--
MY ASP.Net tutorials http://www.openmymind.net/
"NuB" <Nu*@discussion s.microsoft.com > wrote in message
news:95******** *************** ***********@mic rosoft.com... I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
I like the C# code for this. Especially the 2.0 version.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"Karl Seguin [MVP]" <karl REMOVE @ REMOVE openmymind REMOVEMETOO . ANDME
net> wrote in message news:ui******** ******@TK2MSFTN GP15.phx.gbl... cmd.Parameters. Add("@Blah", SqlDbType.Strin g, 128).Value = (firstName == null || firstName.Lengt h == 0) ? DBNull.Value : firstName;
You can do it cleaner in 2.0
cmd.Parameters. Add(....).Value = (string.IsNullO rEmpty(firstNam e) ?? DBNull.Value;
karl
-- MY ASP.Net tutorials http://www.openmymind.net/
"NuB" <Nu*@discussion s.microsoft.com > wrote in message news:95******** *************** ***********@mic rosoft.com...I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
Thanks, I've tried everything listed below, I even did
if (textbox.text == string.Empty)
{
textbox.text = System.DBNull;
}
its an update SQL statement not a proc, so its something like this
update table set name ='" + textbox.text"
now, textbox can be blank on the form, so if it is I need word NULL to show
in the name field in the table
"NuB" wrote: I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
Just don't include the field in the update statement.
Eliyahu
"NuB" <Nu*@discussion s.microsoft.com > wrote in message
news:95******** *************** ***********@mic rosoft.com... I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
something else i just noticed is that the developer that coded this orignally
is using a Control Array of textboxes, will that make a difference in this?
its a collection of textboxes and he's passing the data in the insert query
as an array.
is there anyway to get this working to show NULL in the table instead of a
blank field?
"Eliyahu Goldin" wrote: Just don't include the field in the update statement.
Eliyahu
"NuB" <Nu*@discussion s.microsoft.com > wrote in message news:95******** *************** ***********@mic rosoft.com...I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
Try this...
UPDATE table SET name = NULL
"NuB" wrote: Thanks, I've tried everything listed below, I even did
if (textbox.text == string.Empty) { textbox.text = System.DBNull;
}
its an update SQL statement not a proc, so its something like this
update table set name ='" + textbox.text" now, textbox can be blank on the form, so if it is I need word NULL to show in the name field in the table
"NuB" wrote:
I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db
Nub,
Did you know that you can still use parameters in a text SqlCommand?
It makes them even easier to create:
SqlCommand.Text = "INSERT INTO myTable SET col1 = ?, col2 = ?, col3 = ?,
col4 = ?, col5 = ? WHERE ID = ?"
Each parameter will fill one of the placeholder represented with a question
mark. When doing this you need to specify the parameters in order and you
have to include them all. So combine this with Karl's example and you'll be
all set.
--
Sincerely,
S. Justin Gengo, MCP
Web Developer / Programmer www.aboutfortunate.com
"Out of chaos comes order."
Nietzsche
"NuB" <Nu*@discussion s.microsoft.com > wrote in message
news:D6******** *************** ***********@mic rosoft.com... Thanks, I've tried everything listed below, I even did
if (textbox.text == string.Empty) { textbox.text = System.DBNull;
}
its an update SQL statement not a proc, so its something like this
update table set name ='" + textbox.text" now, textbox can be blank on the form, so if it is I need word NULL to show in the name field in the table
"NuB" wrote:
I have a sql query that is doing an update of records, how can I add NULL to the field in the database if the field on my screen is blank?
example: I have 5 textboxes, and a user can leave some blank, delete data from a text box then hit update, how can I have NULL inserted into the field on the database instead of having a blank record in the db This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: george |
last post by:
This is like the bug from hell. It is kind of hard to explain, so
please bear with me.
Background Info: SQL Server 7.0, on an NT box, Active Server pages
with Javascript, using ADO objects.
I'm inserting simple records into a table. But one insert command is
placing 2 or 3 records into the table. The 'extra' records, have the
same...
|
by: Martin |
last post by:
Hello,
I'm new with triggers and I can not find any good example on how to
do the following:
I have two tables WO and PM with the following fields:
WO.WONUM, VARCHAR(10)
WO.PMNUM, VARCHAR(10)
WO.PROBLEMCODE, VARCHAR(8)
|
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 salvage the records from the many table and without going
into detail, one of the reasons I can't do the opposite as
there are records in the ONE table...
|
by: jtocci |
last post by:
I'm having a big problem with CREATE RULE...ON INSERT...INSERT
INTO...SELECT...FROM...WHERE when I want to INSERT several (20~50)
records based on a single INSERT to a view. Either I get a 'too much
data for field' or the query just runs on and on til I have to restart
the postmaster.
I have found rules to compare mine to but people limit...
|
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then...
| |
by: ImraneA |
last post by:
Hi there
I had pleasure of upsizing Access v97 db to Access v2K/SQL 2K.
Wish to provide some knowledge gained back to community - hopefully
help others.
1.Question how do you test stored procedure from SQL Server vs MS
Access point of view ?
|
by: Abareblue |
last post by:
I have no clue on how to insert a record into access. here is the whole
thing
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
|
by: speralta |
last post by:
My tired old eyes may be failing me, but the following insert
statements look correct to me, but I can't seem to get a clean insert
from a fairly large text file database into mysql. I was wondering if
maybe I'm hitting a limit on character length per line on some insert
statements that I'm trying.
Here's the error messages:
execute...
|
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 file="../Connections/conn.jsp" %>
<%
// *** Edit Operations: declare variables
// set the form action variable
String MM_editAction =...
|
by: gpspocket |
last post by:
help me -CURSOR backward insert from End Date > to Start Date
how to insert dates from end to start
like this
SELECT 111111,1,CONVERT(DATETIME, '17/03/2008', 103), CONVERT(DATETIME, '01/03/2008'
i explain i have stord prosege that create mod cycle shift pattern
and it working ok
|
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...
| |
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...
|
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
|
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...
|
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...
|
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...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
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 we have to send another system
|
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...
| |