Solved

Set value of SQL DB field back to NULL using ASP

Posted on 2009-05-15
10
459 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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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
 
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

815 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

13 Experts available now in Live!

Get 1:1 Help Now