データベースに 2 つのテーブルがあり、1 つの方法で両方のテーブルにデータを保存する必要があります。次のメソッドを実行すると、コードに到達できないというエラーが発生します。このステートメントを単一の挿入ステートメントとして追加する方法を教えてくれる人が必要です。ちなみに、PC_QA_REPORT_1 には主キーがあり、PC_QA_REPORT_2 には外部キーがあります。Project_ID は、この目的のために両方のテーブルで共通の列です。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Web;
using System.Text;
using System.Data.SqlClient;
using System.Xml;
using System.IO;
using System.Data;
namespace WcfService2
{
// NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "Service1" in code, svc and config file together.
public class Service1 : IService1
{
SqlConnection con = new SqlConnection("server = SP-DEV-MACHINE; Initial Catalog=The_Performance; Integrated Security=True");
//public string GetData(int value)
//{
// return string.Format("You entered: {0}", value);
//}
public string SubmitData(string pid, string ptitle, string date, string pqr, string pd, string ps, string pr, string pme, string pef, string pet, string psno, string pqs, string pds, string pmd, string pmr, string pmn)
{
SqlCommand cmd = new SqlCommand("INSERT INTO PC_QA_REPORT_1 (Project_ID, Project_Title, Date, Project_Quality_Rating, Project_Decision, Project_Strategic, Project_Relevant, Project_Monitoring_Eval, Project_Efficient, Project_Effective, Project_Sus_Nat_Own, Project_QA_Summary, Project_Document_Status) VALUES('" + pid + "','" + ptitle + "','" + date + "','" + pqr + "','" + pd + "','" + ps + "','" + pr + "','" + pme + "','" + pef + "','" + pet + "','" + psno + "','" + pqs + "','" + pds + "')", con);
SqlCommand command = new SqlCommand("INSERT INTO PC_QA_REPORT_2 (Project_M_Date, Project_M_Responsibility,Project_M_Notes) VALUES('" + pmd + "','" + pmr + "','" + pmn + "')", con);
con.Open();
int i = cmd.ExecuteNonQuery();
int x = command.ExecuteNonQuery();
con.Close();
return i.ToString();
return x.ToString();
}
//public string MoreData(string pmd, string pmr, string pmn)
//{
// SqlCommand command = new SqlCommand("INSERT INTO PC_QA_REPORT_2 (Project_M_Date, Project_M_Responsibility,Project_M_Notes) VALUES('" + pmd + "','" + pmr + "','" + pmn + "')", con);
// con.Open();
// int x = command.ExecuteNonQuery();
// con.Close();
// return x.ToString();
//}
}
}