vb.net 请教各位:listbox绑定数据后,如何将选取值写入数据库? 20
我的代码如下:SubSure2_Click(SenderAsObject,EAsEventArgs)DimSqlAsStringDimCnnAsOleDbConnecti...
我的代码如下:
Sub Sure2_Click(Sender As Object,E As EventArgs)
Dim Sql As String
Dim Cnn As OleDbConnection
Dim Cmd As OleDbCommand
Dim StrCnn As String
Dim i As Integer
StrCnn = System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_cnnjobok")
Cnn = New OleDbConnection(StrCnn)
Cnn.Open()
For i = 0 To gs_hangye.Items.Count-1
if gs_hangye.Items(i).Selected Then
Sql = "insert into gongsi_yh(gs_email,gs_hangye) values('" & gs_email.Text & "','" & gs_hangye.Items(i).ToString() & "')"
Cmd = New OleDbCommand(Sql, Cnn)
Cmd.ExecuteNonQuery()
End If
Next
Cnn.Close()
end sub
<asp:ListBox ID="gs_hangye" DataSource=" <%# DataSet2.DefaultView %>" DataTextField="hangye" DataValueField="hangye" runat="server" SelectionMode="multiple" Rows="4"> </asp:ListBox>
提交后数据库里没有记录,真着急!!
请高手指点迷津! 展开
Sub Sure2_Click(Sender As Object,E As EventArgs)
Dim Sql As String
Dim Cnn As OleDbConnection
Dim Cmd As OleDbCommand
Dim StrCnn As String
Dim i As Integer
StrCnn = System.Configuration.ConfigurationSettings.AppSettings("MM_CONNECTION_STRING_cnnjobok")
Cnn = New OleDbConnection(StrCnn)
Cnn.Open()
For i = 0 To gs_hangye.Items.Count-1
if gs_hangye.Items(i).Selected Then
Sql = "insert into gongsi_yh(gs_email,gs_hangye) values('" & gs_email.Text & "','" & gs_hangye.Items(i).ToString() & "')"
Cmd = New OleDbCommand(Sql, Cnn)
Cmd.ExecuteNonQuery()
End If
Next
Cnn.Close()
end sub
<asp:ListBox ID="gs_hangye" DataSource=" <%# DataSet2.DefaultView %>" DataTextField="hangye" DataValueField="hangye" runat="server" SelectionMode="multiple" Rows="4"> </asp:ListBox>
提交后数据库里没有记录,真着急!!
请高手指点迷津! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询