Another Check box question...

  • Thread starter Thread starter JJ297
  • Start date Start date
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.
 
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...?
 
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.
 
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
 
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.
 
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
 
.Parameters.AddWithValue("@DisplayedQues", displayedQues)

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

THANKS!
 
Back
Top