VB问题中的SqlParameters SqlDbType.Char [英] SqlParameters SqlDbType.Char in VB Question

查看:134
本文介绍了VB问题中的SqlParameters SqlDbType.Char的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个复选框,我想输入CharY或N

到表格

在C#中我们可以使用例如: - ptrTest.Value = chkYN.Checked? " Y" :

" N"


VB.NET中的等价物是什么?


***通过开发人员指南 http://www.developersdex.com 发送***

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

推荐答案




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


请注意,在VB.NET中它仍会评估双方,即使

表达式只返回真或假


-

Teemu Keiski

ASP.NET MVP,AspInsider

芬兰,欧盟
http://blogs.aspadvice.com/joteke


Thx Teemu做了这个伎俩,但我有另一个问题。


我有一个方法下面,我正在尝试插入一个带ID的复选框

" MessageBank"下面但是'得到


错误: -

对象引用未设置为对象的实例。

on the line" parameterMessageBank.Value = MessageBank.Checked"

方法在一个类中..

我做错了什么?


Public Sub AddProducts(ByVal cartID As String,ByVal productID As

Integer,ByVal quantity As Integer,ByVal MessageBank As

System.Web.UI.WebControls.CheckBox )

''创建连接和命令对象的实例

Dim myConnection As SqlConnection = New

SqlConnection(ConfigurationSettings.AppSettings(" C onnectionString) ;))

Dim myCommand As SqlCommand = New

SqlCommand(" CMRC_ShoppingCartAddItem",myConnection)


''标记命令为SPROC

myCommand.CommandType = CommandType.StoredProcedure


''向SPROC添加参数

Dim parameterProductID作为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 =数量

myCommand.Parameters.Add(parameterQuantity)

Dim parameterMessageBank As SqlParameter = New

SqlParameter(" @ MessageBank",SqlDbType.Bit)

parameterMessageBank.Value = MessageBank.Checked

myCommand.Parameters.Add(parameterMessageBank)

''打开连接并执行命令

myConnection.Open()

MYCO mmand.ExecuteNonQuery()

myConnection.Close()


结束子

***通过Developersdex发送 http://www.developersdex.com ***
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 ***


您是否将CheckBox实例(MessageBank)传递给调用此

方法的方法? (此外,将值传递给

布尔而不是整个控件是不够的?)


7

-

Teemu Keiski

ASP.NET MVP,AspInsider

芬兰,欧盟
http://blogs.aspadvice.com/joteke

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


这篇关于VB问题中的SqlParameters SqlDbType.Char的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆