Solved

Set value of SQL DB field back to NULL using ASP

Posted on 2009-05-15
10
454 Views
Last Modified: 2012-05-07
Once a field in a DB already has a value, can it be set back to NULL using ASP?
0
Comment
Question by:nikinik
  • 6
  • 2
  • 2
10 Comments
 
LVL 9

Expert Comment

by:cdaly33
ID: 24399141
Yes, the specifics depend on what type of data access you're using.
0
 

Author Comment

by:nikinik
ID: 24399193
I don't understand your question.  I'm accessing a SQLServer 2005 DB via ASP.
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 24399240
It used to be that in Enterprise Manager/Sql Server Managerment Studio if you were selected on the field that you wanted set to null and pressed Ctrl-0 and then leave the field. I havent tried it in a long time.

If you are trying to set it programatically using .net or something then it depends on what language you are using as to how to accomplish this.

dday
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 24399256
Ok so I was curious if it still worked...it does :)
0
 
LVL 9

Expert Comment

by:cdaly33
ID: 24399265
Are you using a ADO or a custom provider?  Are you accessing stored procedures or doing direct updates to the data?
0
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 
LVL 20

Expert Comment

by:ddayx10
ID: 24399299
Sorry to stretch these out...little quirky today I guess.

Ex of how to set null value programatically (one of many ways depending on how accessing db):
VB: Dim p As SqlParameter = New SqlParameter("@p", DBNull.Value)

C#: sqlParameter p = new sqlParameter("@p",DBNull.Value);

dday
0
 

Author Comment

by:nikinik
ID: 24399371
As stated in the original question...I'm trying to do it programatically in ASP.
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 24399447
I understand that, but you didnt see what language you were using in ASP (C#, VB, etc) and you didnt give any context so I had a little fun and showed you both programmatically (see posts above), and using the database management tools.

If you would like a more specific example of how to set the value to null it would be necessary to see the context of the code you are trying to use.

Here's another example:
Dim uStatement as string =  "DBNull.Value & WHERE tblColumn2 = 1"
Dim conn as New SqlDataConnection([ConnectionStringGoesHERE])
Dim cmd as New SqlCommand(uStatement,Conn)

later....

dday

0
 
LVL 20

Accepted Solution

by:
ddayx10 earned 500 total points
ID: 24399470
ooo I botched the uStatement... where is my head today?

Here's another example:
Dim uStatement as string =  "UPDATE tbl SET tblColumn =" & DBNull.Value & "WHERE tblColumn2 = 1"
Dim conn as New SqlDataConnection([ConnectionStringGoesHERE])
Dim cmd as New SqlCommand(uStatement,Conn)
0
 
LVL 20

Expert Comment

by:ddayx10
ID: 24399520
lol "B" that's pretty critical considering....thanks all the same and you are welcome :)
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now