问题描述
我想从用户中提取admission_no,但我不想要phone_no,并且将其与test_test中的所有数据合并为admission_no.之后,我想将它们插入到合并表的一个表中.
示例表
用户
mission_no,phone_no
testo
subject_id,subject_name,admission_no,日期,时间,地点,seat_no
合并
subject_id,subject_name,admission_no,日期,时间,地点,seat_no
我应该如何在C#中执行此操作?请帮助..
以下是我当前的密码..
I want to extract admission_no from users but I don''t want the phone_no and merge with admission_no with all the data from test. After that I want to insert them into one table which is the merge table.
Example Tables
users
admission_no,phone_no
testo
subject_id,subject_name,admission_no,date,time,venue,seat_no
merge
subject_id,subject_name,admission_no,date,time,venue,seat_no
HOW AM I SUPPOSE TO DO THAT IN C#?PLEASE HELP..
BELOW IS MY CURRENT CODES..
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Data Source= EN12-2-20-PC01\\SQLEXPRESS;" + "Initial Catalog=ssms;Integrated Security=SSPI");
SqlDataAdapter adapSel;
conn.Open();
foreach (GridViewRow gvr in GridView2.Rows) //loop through GridView
{
string viewqry = "INSERT INTO merge(subject_id,subject_name,admission_no,date,time,venue,seat_no) " + "(SELECT U.admission_no,T.subject_name,T.date,T.time,T.venue,T.seat_no " + "From users As U INNER JOIN testo As T ON U.admission_no = T.admission_no) VALUES (''" + gvr.Cells[0].Text + "'',''" + gvr.Cells[1].Text + "'',''" + gvr.Cells[2].Text + "'',''" + gvr.Cells[3].Text + "'',''" + gvr.Cells[4].Text + "'',''" + gvr.Cells[5].Text + "'',''" + gvr.Cells[6].Text + "'')";
adapSel = new SqlDataAdapter(viewqry, conn);
DataSet dsSel = new DataSet();
adapSel.Fill(dsSel);
GridView2.DataSource = dsSel;
GridView2.DataBind();
conn.Close();
}
推荐答案
INSERT INTO table VALUES (value1, value2, value3,...)
INSERT INTO table (column1, column2, column3,...) VALUES (value1, value2, value3,...)
INSERT INTO table SELECT column1, column2, column3,... FROM othertable
INSERT INTO table (column1, column2, column3,...) SELECT column1, column2, column3,... FROM othertable
这篇关于我的代码有什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!