复制数据库中的数据集合 [英] copy collection of data in database

查看:77
本文介绍了复制数据库中的数据集合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好。

i有表女巫有课程(course_id,course_name,Course_class)

我有表course_student(student_id,course_id)

Hello everybody
i have table witch have the courses(course_id,course_name,Course_class)
and i have table course_student(student_id,course_id)

string cmdstr4 = "select course_id from courses where class_name='" + std_class.ToString() + "'";
          SqlCommand slctCourseid = new SqlCommand(cmdstr4, con);
          slctCourseid.ExecuteNonQuery();
          string cmdstr000 = "insert into [course_students] values(" + stdid + "," + course_id + ")";
          SqlCommand inserstdtocourse = new SqlCommand(cmdstr000, con);
          inserstdtocourse.ExecuteNonQuery();



i想要将同一课程的所有课程复制到表格(course_students)

和id学生在每个课程ID旁边都是惰性的。

thnx很多


i want to copy all the courses which are for the same class to the table(course_students)
and the id of the student inert it beside each course id.
thnx alot

推荐答案

1.首先获得属于特定课程的所有课程ID 2.上面你可以存储在一个DataSet中。

3.启动一个循环,这个循环将持续到数据集中有一行。

4.对于每一行,将课程ID插入course_student表。

5.使用sql事务执行此操作以使其成为现实。





一切顺利。如果您遇到任何问题,请告诉我。
1.First of all get all the course ids that belongs to a Particular class.
2.The above you can store in a DataSet.
3.Start a loop that will continue till there is a row n the dataset.
4.For each row insert the course id to the course_student table.
5.Perform this by using the sql transaction in order to make it happen.


All the best.Let me know if you will face any problem.


这篇关于复制数据库中的数据集合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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