473,503 Members | 2,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SqlParameters SqlDbType.Char in VB Question

I have a checkbox and i want to input Char "Y" or "N"
to the Table
In C# we could use for example :- ptrTest.Value = chkYN.Checked ? "Y" :
"N";

Whats the equivalent in VB.NET?


*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #1
10 3961
Hi,

IIF function
http://msdn.microsoft.com/library/de...l/vafctiif.asp

Just be aware that in VB.NET it still evaluates both sides even though the
expression returns only True or False

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Nov 19 '05 #2
Thx Teemu that did the trick but i have another Question.

I have a method below and i'm trying to insert a checkBox with ID
"MessageBank" below but 'm getting

Error:-
Object reference not set to an instance of an object.
on the line "parameterMessageBank.Value = MessageBank.Checked"
The Method is in a Class..
What am i doing wrong?

Public Sub AddProducts(ByVal cartID As String, ByVal productID As
Integer, ByVal quantity As Integer, ByVal MessageBank As
System.Web.UI.WebControls.CheckBox)
' Create Instance of Connection and Command Object
Dim myConnection As SqlConnection = New
SqlConnection(ConfigurationSettings.AppSettings("C onnectionString"))
Dim myCommand As SqlCommand = New
SqlCommand("CMRC_ShoppingCartAddItem", myConnection)

' Mark the Command as a SPROC
myCommand.CommandType = CommandType.StoredProcedure

' Add Parameters to SPROC
Dim parameterProductID As SqlParameter = New
SqlParameter("@ProductID", SqlDbType.Int, 4)
parameterProductID.Value = productID
myCommand.Parameters.Add(parameterProductID)

Dim parameterCartID As SqlParameter = New
SqlParameter("@CartID", SqlDbType.NVarChar, 50)
parameterCartID.Value = cartID
myCommand.Parameters.Add(parameterCartID)

Dim parameterQuantity As SqlParameter = New
SqlParameter("@Quantity", SqlDbType.Int, 4)
parameterQuantity.Value = quantity
myCommand.Parameters.Add(parameterQuantity)

Dim parameterMessageBank As SqlParameter = New
SqlParameter("@MessageBank", SqlDbType.Bit)
parameterMessageBank.Value = MessageBank.Checked
myCommand.Parameters.Add(parameterMessageBank)
' Open the connection and execute the Command
myConnection.Open()
myCommand.ExecuteNonQuery()
myConnection.Close()

End Sub
*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #3
Do you pass the CheckBox instance (MessageBank) to the method where this
method is called? (Besides, wouldn't it be enough to just pass the value as
Boolean instead of entire Control?)

7
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

Nov 19 '05 #4
Yeah i could pass it as Boolean but wouldn't i have to have the value of
the checkBox checked?And if i assign CheckBox1.Checked to the value it
says its not a member of Boolean.

Any way let me explain my scenario in details :-
I have CheckBox in my webform with a Datalist like so-

<table width="300" border="0">
<tr>
<td>
<asp:CheckBox ID="MessageBank" Runat="server"></asp:CheckBox>
</td>
</tr>
</table>
<asp:datalist id="MyList" runat="server" RepeatColumns="2">
<ItemTemplate>
<td width="100" valign="middle" align="right">
<a href='ProductDetails.aspx?productID=<%#
DataBinder.Eval(Container.DataItem, "ProductID") %>'>
<img src='ProductImages/thumbs/<%#
DataBinder.Eval(Container.DataItem, "ProductImage") %>' width="100"
height="75" border="0">
</a>
</td>
<td width="200" valign="middle">
href='ProductDetails.aspx?productID=<%#
DataBinder.Eval(Container.DataItem, "ProductID") %>'>
<span class="ProductListHead">
<%# DataBinder.Eval(Container.DataItem, "ModelName") %>
</span><br>
</a>
<a href='AddToCart.aspx?productID=<%#
DataBinder.Eval(Container.DataItem, "ProductID") %>'>
<font color="#9D0000"><b>Add To Cart<b></font></span>
</a></td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>

The Datalist displays products that would be added to a Cart by
clicking the AddToCart.aspx with the ProductID link above.But i want the
user to select the checkbox and would like to pass the value to
AddToCart page.

In AddToCart.aspx codebhind i call a Public Method called AddProduct
that inserts the Products

cart.AddProduct(cartId, CInt(Request.Params("ProductID")), 1,
MessageBank)

Below is the Method in the Class that inserts the products
----------------------------------------------------------
Public Sub AddProduct(ByVal cartID As String, ByVal productID As
Integer, ByVal quantity As Integer, ByVal MessageBank As Boolean)

Dim parameterMessageBank As SqlParameter = New
SqlParameter("@MessageBank", SqlDbType.Bit)
parameterMessageBank.Value = MessageBank
myCommand.Parameters.Add(parameterMessageBank)

My Question is how would i pass the selected checkBox(MessageBank) to
the AddProduct and i want to insert 1 or 0 to the MessageBank field so
if checked it inserts 1 and if not 0.

Thanks



*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #5
Hello,

I see.

The problem is that you link to another page (you use normal <A> with hrefs)
and that other page has no knowledge about the CheckBox on this, sending
page (the one you click link on). You'd need to change it so that you cause
a postback back to this page (using Button or LinkButton etc), handle that
in DataList's ItemCommand (there you could get data about the checked status
of the CheckBox) and redirect to the other page (, if you need to do it on
another page).
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Patrick Olurotimi Ige" <na********@hotmail.com> wrote in message
news:Oj**************@tk2msftngp13.phx.gbl...
Yeah i could pass it as Boolean but wouldn't i have to have the value of
the checkBox checked?And if i assign CheckBox1.Checked to the value it
says its not a member of Boolean.

Any way let me explain my scenario in details :-
I have CheckBox in my webform with a Datalist like so-

<table width="300" border="0">
<tr>
<td>
<asp:CheckBox ID="MessageBank" Runat="server"></asp:CheckBox>
</td>
</tr>
</table>
<asp:datalist id="MyList" runat="server" RepeatColumns="2">
<ItemTemplate>
<td width="100" valign="middle" align="right">
<a href='ProductDetails.aspx?productID=<%#
DataBinder.Eval(Container.DataItem, "ProductID") %>'>
<img src='ProductImages/thumbs/<%#
DataBinder.Eval(Container.DataItem, "ProductImage") %>' width="100"
height="75" border="0">
</a>
</td>
<td width="200" valign="middle">
href='ProductDetails.aspx?productID=<%#
DataBinder.Eval(Container.DataItem, "ProductID") %>'>
<span class="ProductListHead">
<%# DataBinder.Eval(Container.DataItem, "ModelName") %>
</span><br>
</a>
<a href='AddToCart.aspx?productID=<%#
DataBinder.Eval(Container.DataItem, "ProductID") %>'>
<font color="#9D0000"><b>Add To Cart<b></font></span>
</a></td>
</tr>
</table>
</ItemTemplate>
</asp:datalist>

The Datalist displays products that would be added to a Cart by
clicking the AddToCart.aspx with the ProductID link above.But i want the
user to select the checkbox and would like to pass the value to
AddToCart page.

In AddToCart.aspx codebhind i call a Public Method called AddProduct
that inserts the Products

cart.AddProduct(cartId, CInt(Request.Params("ProductID")), 1,
MessageBank)

Below is the Method in the Class that inserts the products
----------------------------------------------------------
Public Sub AddProduct(ByVal cartID As String, ByVal productID As
Integer, ByVal quantity As Integer, ByVal MessageBank As Boolean)

Dim parameterMessageBank As SqlParameter = New
SqlParameter("@MessageBank", SqlDbType.Bit)
parameterMessageBank.Value = MessageBank
myCommand.Parameters.Add(parameterMessageBank)

My Question is how would i pass the selected checkBox(MessageBank) to
the AddProduct and i want to insert 1 or 0 to the MessageBank field so
if checked it inserts 1 and if not 0.

Thanks



*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #6
Thats what i came to find out too but i'm still not getting how to pass
the values corretly..
If i use linkButton or Button how would i use it to cause postback?
Can you show me how i can handle that in the DataList's ItemCommand?
Thanks
*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #7
Declare a LinkButton instead of the link (in the <ItemTemplate>) and bind
the ID to the CommandArgument

<asp:LinkButton ID="Link1" runat="server" CommandName="link"
CommandArgument='<%#
DataBinder.Eval(Container.DataItem, "ProductID") %>' />

This will automatically cause DataList's ItemCommand event to be raised
(just wire an event handler to it)

Protected Sub DataList1_ItemCommand(sender As Object, ce As
CommandEventArgs) Handles DataList1.ItemCommand

If ce.CommandName="link" Then
'Get cheked status
Dim checked As Boolean=MessageBan.Checked

'Get the ID from CommandArgument
Dim productID As Integer=Cint(ce.CommandArgument)

'And continue from here, either redirecting to another page with
params in querystring
' or do the adding already on this method like on following line
'cart.AddProduct(cartId, productID, 1,checked)

End If

End Sub
--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke

"Patrick Olurotimi Ige" <na********@hotmail.com> wrote in message
news:OO*************@TK2MSFTNGP10.phx.gbl...
Thats what i came to find out too but i'm still not getting how to pass
the values corretly..
If i use linkButton or Button how would i use it to cause postback?
Can you show me how i can handle that in the DataList's ItemCommand?
Thanks
*** Sent via Developersdex http://www.developersdex.com ***

Nov 19 '05 #8
Thx Teemu for the reply.
I ended up passing it in the querystring
But i would change it your approach later.
Patrick
*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #9
Teemu thx for the reply.
After trying to use what you adviced by using the LinkButton.
The LinkButton is placed in A DataList.
The hyperlink i'm going to use is looking like this:-
NavigateUrl='<%#"AddToProduct.aspx?productID=" &
DataBinder.Eval(Container, "DataItem.ProductID").
How can i pass that to the CommandArgument?

The AddProduct.aspx page is going to add the Params to the Database by
calling the method below:-
cart.AddProduct(cartId, productID, 1,checked)

If i use your approach
Dim checked As Boolean=MessageBan.Checked
where am i i going to define the CheckBox?
Thanks Patrick

*** Sent via Developersdex http://www.developersdex.com ***
Nov 19 '05 #10
If you have it on Page at top-level, accessing it that way is just fine
(control on Page and then via its member). If it is contained in the same
Item you could run FindControl (e.Item.FindControl("messageBan") to find it)

--
Teemu Keiski
ASP.NET MVP, AspInsider
Finland, EU
http://blogs.aspadvice.com/joteke
Nov 19 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
1446
by: smartbeginner | last post by:
Hello, My pgm is main() { char *c; printf("\n Size of c is %d",sizeof(c)); c="Im a beginner"; printf("\n Size of string c is %d",sizeof(c)); }
3
1909
by: Zach | last post by:
Hello, This might be a rather basic question, but I've tried a few things and I can't really find a solution as elegant as what I'd like for this problem. The situation is this - I have a file...
9
1061
by: Joseph Lu | last post by:
Hi, all I use the following codes to create a char array with only three elements, /------------------------ char *strHead = new char; bytesin=(DWORD)strlen(strHead)...
15
1796
by: RAB | last post by:
I am programming in the palm environment using C++ and am stuck. I have created an char array: const char MyArray = { {"string1"}, {"string2"}, .... {"string50"} }
1
1393
by: tryptik | last post by:
I am implimenting an IO function that will write numeric types (int, long, double, etc) in binary format. I am casting them to a char* in order to implement byte-swapping from big-endian to...
0
7188
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7258
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
6970
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7441
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5558
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4987
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3156
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3146
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1489
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.