我有 2 个表,即 Profile 和 Info。
我的桌子看起来像这样:
轮廓
| p_Id | FirstName | LastName |
| 1 | Jack | Cole |
| 2 | Cynthia | Cole |
| 3 | Robert | Cole |
信息
| I_Id | childsID | fathersID | mothersID | Country |
| 1 | 1 | 3 | 2 | USA |
我通过在文本框中显示这些表中的值来检索它们,我的选择查询是:
SELECT p.p_Id, p.FirstName, p.LastName, i.*,
(SELECT pp.FirstName+' '+pp.LastName FROM Profile pp WHERE pp.p_Id=i.childsID) AS child,
(SELECT pp.FirstName+' '+pp.LastName FROM Profile pp WHERE pp.p_Id=i.fathersID) AS father,
(SELECT pp.FirstName+' '+pp.LastName FROM Profile pp WHERE pp.p_Id=i.mothersID) AS mother
FROM Info i
INNER JOIN Profile p
ON p.p_Id=i.childsID
选择没问题,我可以在文本框中显示值,但问题是,我无法更新它们,到目前为止我已经尝试过:
using (SqlCommand cmd = con.CreateCommand())
{
con.Open();
cmd.CommandText = @"UPDATE Profile SET FirstName=@fname, LastName=@lname WHERE p_Id = @pid;
UPDATE Info SET childsID=@child, fathersID=@father, mothersID=@mother, Country=@country WHERE I_Id = @iid;";
cmd.Parameters.Add(new SqlParameter("@fname", txtfname.Text));
cmd.Parameters.Add(new SqlParameter("@lname", txtlname.Text));
cmd.Parameters.Add(new SqlParameter("@child", txtchild.Text));
cmd.Parameters.Add(new SqlParameter("@father", txtfather.Text));
cmd.Parameters.Add(new SqlParameter("@mother", txtmother.Text));
cmd.Parameters.Add(new SqlParameter("@country", txtcountry.Text));
cmd.Parameters.Add(new SqlParameter("@pid", txtpid.Text));
cmd.Parameters.Add(new SqlParameter("@iid", txtiid.Text));
cmd.ExecuteNonQuery();
Response.Write("alert('DATA UPDATED')");
}
我正在使用 c# 和 Asp.net 在此先感谢 :) 上帝保佑