如何从文本框到数据库中插入具有相同值的Checkedlistbox的多个值 [英] How I Can Insert Multiple Values Of Checkedlistbox With A Same Value From A Textbox Into Database

查看:75
本文介绍了如何从文本框到数据库中插入具有相同值的Checkedlistbox的多个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在学生出勤表格中,当检查了多个复选框并且教师必须保存它时,我已检查了核对清单箱中特定批次的所有学生,我想将其存储在数据库(具有属性BatchNo,TeacherID,StudentID的表)中这个插入batchNo和teacherID将是相同的,倍数StudentID将与它们一起存储。来自CheckedListBox。

提前谢谢

In student attendance form i have retrieved all students of a specific batch in a checkedlistbox when multiples check boxes are checked and teacher has to save it, i want to store it in database (table having attributes BatchNo, TeacherID, StudentID) in this insertion batchNo and teacherID will be same and multiples StudentID's will be stored along with them. from CheckedListBox.
Thanks in advance

推荐答案

您可以使用表值参数将整个表传递给sql存储过程。



点击链接



http://msdn.microsoft.com/en-us/library/bb510489.aspx [ ^ ]
You can use table valued parameter to pass entire table to sql stored procedure.

follow the link

http://msdn.microsoft.com/en-us/library/bb510489.aspx[^]


public void InsertData()
{
foreach (ListItem item in CheckBoxList.Items)
{
if (item.Checked)
{
con.Open();
String str = "Insert into imtiaz values('" + CheckBoxList1.SelectedValue + "')";
SqlCommand cmd = new SqlCommand(str, con);
int i = cmd.ExecuteNonQuery();

con.Close();
}


这篇关于如何从文本框到数据库中插入具有相同值的Checkedlistbox的多个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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