Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

variable for checkbox passing 1 to sql when checked not workong

Status
Not open for further replies.

melrse

Programmer
Dec 13, 2000
25
US
Dim FcommunicationR As Integer
Dim p27 As New SqlParameter("@Quest24communication", FcommunicationR)
If Fcommunication.Checked = True Then
FcommunicationR = 1
End If
cmdInsert.Parameters.Add(p27)
<asp:CheckBox ID="Fcommunication" runat="server" Text="Communication" />

This does not error out but I do not get the value of 1 in my smallinteger field in sql when the checkbox is checked. I know I am missing something I think in the dim p27 that is not passing the actual value of Fcommincation 1. Thanks
 
Try

Code:
Dim FcommunicationR As Integer

If Fcommunication.Checked = True Then
            FcommunicationR = 1
End If

Dim p27 As New SqlParameter("@Quest24communication", FcommunicationR)
cmdInsert.Parameters.Add(p27)
 <asp:CheckBox ID="Fcommunication" runat="server" Text="Communication" />

In order to avoid this kind of mistakes, you should understand the difference between value types and reference types.
2 quite interesting articles on the subject :

Memory in .NET - what goes where - Introduction

When to Pass VB.NET Arguments as Reference Types Versus Value Types


Hope this helps!

---
[tt][COLOR=white Black]MASTA[/color][COLOR=Black lightgrey]KILLA[/color][/tt] [pipe]
 
Try this instead:
Code:
Dim FcommunicationR As Integer
If Fcommunication.Checked = True Then
    FcommunicationR = 1
End If
Dim p27 As New SqlParameter("@Quest24communication", FcommunicationR)
cmdInsert.Parameters.Add(p27)

Senior Software Developer
 
[noevil]

---
[tt][COLOR=white Black]MASTA[/color][COLOR=Black lightgrey]KILLA[/color][/tt] [pipe]
 
thank you so very very much. i have been debugging and no avail. i so appreciate your help. thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top