我正在尝试从C#网络表单按下按钮,将表1中的数据插入到表2中。我只是将表1中的问题编号附加到表2,但我无法弄清楚如何添加从表单中添加的额外细节。 (DateStamp,用户)等
SqlConnection conn10000 = new SqlConnection(ConfigurationManager.ConnectionStrings["ESRConnectionString"].ConnectionString);
conn10000.Open();
string AppendQuestions = "INSERT INTO Table2 " +
" (StressQuestionNumber, StressQuestionnaireID, CreatedBy, CreateDate) VALUES( " +
"SELECT StressQuestionNumber " +
"FROM Table1, " +
"@StressQuestionnaireID, @CreatedBy, @CreateDate )";
SqlCommand com10000 = new SqlCommand(AppendQuestions, conn10000);
com10000.Parameters.AddWithValue("@StressQuestionnaireID", StressID);
com10000.Parameters.AddWithValue("@CreatedBy", Session["sesUserLogIn"]);
com10000.Parameters.AddWithValue("@CreateDate", DateTime.Now);
com10000.ExecuteScalar();
conn10000.Close();
答案 0 :(得分:0)
像
这样的东西INSERT INTO Table2
(
StressQuestionNumber, StressQuestionnaireID, CreatedBy, CreateDate
)
SELECT StressQuestionNumber, @StressQuestionnaireID, @CreatedBy, @CreateDate
FROM Table1