我有一个名为listbox
的列表框。其“多选”属性设置为true
。我需要将此列表框中的选择存储到数据库字段中。在数据库中存储多个ListBox选择?
请注意,我正在使用Web窗体,ASP.NET,C#和Visual Studio Web Developer 2010 Express。
我的代码如下:
SqlCommand insertNL = new SqlCommand("insert into dbo.newsletter (newsletter_subject,newsletter_body,newsletter_sentto) VALUES ('" + TextBox1.Text + "', '" + TextBox2.Text + "', '" + ListBox1.SelectedItem + "')", badersql);
badersql.Open();
insertNL.ExecuteNonQuery();
badersql.Close();
不幸的是,这个代码只存储在我的newsletter
表的“newsletter_sentto
”列ListBox的第一选择的值。有没有人有任何建议如何解决这个代码?提前致谢。
这些答案都没有解决您的问题吗?如果是这样,请选择那个“正确”。如果没有,编辑你的问题和/或添加评论,以更好地阐明你的后,你可以得到更好的答案。 – 2010-12-15 20:31:04