Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / August 2007

Tip: Looking for answers? Try searching our database.

Another Check box question...

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JJ297 - 14 Aug 2007 12:59 GMT
Can't get null into the database.   I'm trying to achieve...

if displayedQues = "Y" then I want nondisplayedques to go into the
database as null.  What do I need to do?  This is what I have thus
far.

Dim displayedQues As Char = "Y"
Dim nonDisplayedQues As Char = "N"

If (RadioYes.Checked) Then
           displayedQues = "Y"
       End If

If (RadioNo.Checked)  Then
     nonDisplayedQues = "N"
       End If

Thanks for your assistance.
Mark Rae [MVP] - 14 Aug 2007 13:09 GMT
> What do I need to do?

Difficult to say with what you've provided so far...

Are you building up dynamic SQL (hopefuly not!), or are you using a
paremeterised query...?

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

JJ297 - 14 Aug 2007 13:16 GMT
> > What do I need to do?
>
[quoted text clipped - 6 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

Not sure what you mean.  I have two check boxes on the design page
that ask user to select yes or no if they want their question
displayed on the FAQ sheet.

On button click I have the above code.  I wanted if the answer is yes
then put a Y in the database for Yes and Null for N.
Mick Walker - 14 Aug 2007 13:19 GMT
>>> What do I need to do?
>> Difficult to say with what you've provided so far...
[quoted text clipped - 12 lines]
> On button click I have the above code.  I wanted if the answer is yes
> then put a Y in the database for Yes and Null for N.

If [CheckBox].Checked = True Then
    ' Do something
Else
    ' Do something Else
End if
Mick Walker - 14 Aug 2007 13:21 GMT
>>> What do I need to do?
>> Difficult to say with what you've provided so far...
[quoted text clipped - 12 lines]
> On button click I have the above code.  I wanted if the answer is yes
> then put a Y in the database for Yes and Null for N.

Ignore my previous post. I misread your question.

You need to provide us with some of your database logic, at the moment
your telling us nothing about how you are achiving the database insert,
or any structure of the table concerned.
JJ297 - 14 Aug 2007 13:31 GMT
> >> "JJ297" <nc...@yahoo.com> wrote in message
>
[quoted text clipped - 24 lines]
>
> - Show quoted text -

Sorry about that... here's the code behind page:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Button1.Click
       Dim question As String = TxtQuestion.Text
       Dim answer As String = TxtAnswer.Text

       Dim CDPPin As String = Session("GetPin")

       Dim displayedQues As Char = "Y"
       Dim nonDisplayedQues As Char = "N"

       Dim conn As New Data.SqlClient.SqlConnection("Data
Source=seb2a54;Initial Catalog=EDCSFAQS;Persist Security
Info=True;User ID=EDCSFAQUser;Password=fax") 'this is the conn from
frontpage

       If (RadioYes).Checked = True Then
           displayedQues = "Y"
       Else : displayedQues = ""

       End If

       If (RadioNo).Checked = True Then
           nonDisplayedQues = "N"
       Else : nonDisplayedQues = ""
       End If

       Dim cmd As New Data.SqlClient.SqlCommand
       With cmd
           .Connection = conn 'the connection
           .CommandType = Data.CommandType.StoredProcedure
           .CommandText = "EnterAdminQuestion"
           .Parameters.AddWithValue("@topicid",
CInt(DropDownList1.SelectedItem.Value))
           .Parameters.AddWithValue("@quesdate", QuesDate.Text)
           .Parameters.AddWithValue("@questions", TxtQuestion.Text)
           .Parameters.AddWithValue("@Answer", TxtAnswer.Text)
           .Parameters.AddWithValue("@DisplayedQues", displayedQues)
           .Parameters.AddWithValue("@NonDisplayedQues",
nonDisplayedQues)
           .Parameters.AddWithValue("@CDPPin", CDPPin)
       End With

       Try
           conn.Open()
           cmd.ExecuteNonQuery()

       Catch ex As Data.SqlClient.SqlException
           Throw New ApplicationException("An error occurred while
trying to insert the record")
       Finally
           conn.Close()
       End Try

       Lbloutcome.Text = "Your entry was submitted into the
database."

   End Sub
Mark Rae [MVP] - 14 Aug 2007 14:02 GMT
>            .Parameters.AddWithValue("@DisplayedQues", displayedQues)

If (RadioYes).Checked = True Then
   .Parameters.AddWithValue("@DisplayedQues", displayedQues)
Else
   .Parameters.AddWithValue("@DisplayedQues", System.DbNull.Value)
End If

Signature

Mark Rae
ASP.NET MVP
http://www.markrae.net

JJ297 - 14 Aug 2007 14:28 GMT
> >            .Parameters.AddWithValue("@DisplayedQues", displayedQues)
>
[quoted text clipped - 7 lines]
> Mark Rae
> ASP.NET MVPhttp://www.markrae.net

THANKS!

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.