在数据库中插入数据的条件

时间:2013-06-24 08:03:57

标签: vb.net ado.net combobox

这是我的场景。

 I have a combo box which has 8 items. {items : a,b,c,d,e,f,g,h}

我有一个包含Employee列的表。

if  i select a and when i insert that into my database table,it should be 1
if  i select b and when i insert that into my database table,it should be 1  and so on for 8 items.

我正在尝试的是:

objSQLParms(12) = New SqlParameter("@Employee_Type", SqlDbType.SmallInt)
       If cmbList.Text.Trim = "Employee" Then
            If cmbemployee.Text.Trim.Length = 0 Then
                objSQLParms(12).Value = 0
            Else
                objSQLParms(12).Value = cmbemployee.Text.Trim.Substring(0, 1)
            End If
        Else
            objSQLParms(12).Value = 0

通过执行此操作,我只获得组合框中存在的值。 如何在此场景中编写案例以获取数字。

提前致谢

2 个答案:

答案 0 :(得分:0)

你有这样的尝试吗?

If cmbemployee.Text.Trim.Length = 0 Then
     objSQLParms(12).Value = 0
Else
     objSQLParms(12).Value = val(cmbemployee.Text.Trim.Substring(0, 1))
End If

答案 1 :(得分:0)

因为当您触发按钮事件插入数据库时 页面回发了 和组合框值设置为默认值“a”

你可以通过在更新面板中放置combobox来解决它 避免重新加载页面