我的数据库中有 2 个表,我需要以一种方法将数据保存到两个表中。执行以下方法时出现代码无法访问的错误。我需要有人告诉我如何将此语句添加为单个插入语句。顺便说一下,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();
//}
}
}