【问题标题】:proper usage of apostrophe in sql statements to call combo box在sql语句中正确使用撇号来调用组合框
【发布时间】:2013-03-25 05:37:44
【问题描述】:

如何更改“COMP”以检查我在组合框类别中选择的内容?

我的文本框是 cmbCategory

cmd = New SqlCommand("SELECT * FROM tblOfficeEquipmentSubCategory Where CAT_ID='COMP'", sqlconn)
If sqlconn.State = ConnectionState.Closed Then sqlconn.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
sdr.Close()

【问题讨论】:

标签: sql vb.net combobox


【解决方案1】:

试试这样的:

cmd = New SqlCommand("SELECT * FROM tblOfficeEquipmentSubCategory Where CAT_ID=@Category", sqlconn)
cmd.Parameters.Add("@Category", SqlDbType.NVarChar, -1).Value = cmbCategory.SelectedText
If sqlconn.State = ConnectionState.Closed Then sqlconn.Open()
Dim sdr As SqlDataReader = cmd.ExecuteReader()
sdr.Close()

【讨论】:

  • 先生它返回错误附加信息:无效参数大小值'-1'。该值必须大于或等于 0。我可以注意到这一点。这是一个组合框,当我选择一个类别时,它将在组合框 2 上显示相应的子类别
  • size 设置为 1000 或任何您需要的值:cmd.Parameters.Add("@Category", SqlDbType.NVarChar, 1000)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-10-06
  • 2012-08-28
  • 2013-08-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多