Another Check box question...

J

JJ297

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

Mark Rae [MVP]

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...?
 
J

JJ297

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

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

Mick Walker

JJ297 said:
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.
If [CheckBox].Checked = True Then
' Do something
Else
' Do something Else
End if
 
M

Mick Walker

JJ297 said:
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.
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.
 
J

JJ297

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.- Hide quoted text -

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

Mark Rae [MVP]

.Parameters.AddWithValue("@DisplayedQues", displayedQues)

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

JJ297

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

THANKS!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,265
Latest member
TodLarocca

Latest Threads

Top