如何在一个表中插入两个表格的记录 [英] how to insert the records of two tabels in one table

查看:87
本文介绍了如何在一个表中插入两个表格的记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HI


i希望通过使用带有c#的asp.net插入querry来在一个表格中插入两个表格的记录但是记录未插入我的代码是





HI
i want to insert record of two tabels in one tabel by inserting querry using asp.net with c# but records are not inserting my code is that


SqlConnection sq = new SqlConnection(connectionString);
                SqlCommand cm;
                sq.Open();
                cm = new SqlCommand("INSERT INTO Result(Semester,TotalMarks,MarksTheory,MarksLab,GPA,Status)(Select student_id,FullName,FatherName,Class,Program FROM Student)) Values('" + Nametxt.Text + "','" + Fathertxt.Text + "','" + DropDownclass.SelectedValue + "','" + DropDownSmster.SelectedValue + "','" + TotalMarkstxt.Text + "','" + Markstheorytxt.Text + "','" + Markslabtxt.Text + "','" + GPAtxt.Text + "','" + DropDownStatus.SelectedValue + "','" + DropDownProgram.SelectedValue + "')", sq);
                cm.ExecuteNonQuery();
                sq.Close();

推荐答案

1.如果表的结构相同而你想插入每一个来自两个表的记录比你可以使用它:

1.if the structure of your tables is same and you want to insert every record from both tables than you can use this :
INSERT INTO table1 (col1,col2,col3,.....,coln) 
     SELECT * FROM table2, table3



2.如果您想根据某些条件插入特定记录,而不是使用此条件:


2.if you want to insert specific records based on some condition than you can use this:

INSERT INTO table1 (col1,col2,col3,.....,coln) 
     SELECT * FROM table2, table3 where table2.colname=table3.colname



你可以在where子句中使用你自己的条件


you can use your own condition in "where" clause


这篇关于如何在一个表中插入两个表格的记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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