我想从1个表中获取两个记录,并将该记录插入另一个表,其ID已存储在第二个表中,请查看下面的示例。 enter image description here
当您查看表格时,现在有针对跟踪ID上传的图片我希望针对该跟踪插入更多图片,而createDate和Project_ID来自另一个表格
这是我的商店程序
create proc spinsertMoreImages
@TrackerID int ,
@PhotoName varchar(50),
@PhotoDynamicName varchar(50) ,
@IsActive bit = null
as
begin
insert into tblFilePhoto (Tracker_ID , Photo_Name , CreateDate , Project_ID , PhotoDynamicName , IsActive)
select LetterCreateDate, Project_Id from tblFileTracker where Tracker_ID = @TrackerID;
end
这是我的Aspx.cs代码
protected void btnUpload_Click(object sender, EventArgs e)
{
clsFileTracker objLetter = new clsFileTracker();
foreach (HttpPostedFile htfiles in uplImage.PostedFiles)
{
var guid = Guid.NewGuid();
var path = guid.ToString() + ".jpg";
StrName = Path.GetFileNameWithoutExtension(htfiles.FileName);
htfiles.SaveAs(Server.MapPath("~/upload/") + path);
objLetter.SaveMoreImage(StrName, txtLetterCreateDate.Text, ddlProject.SelectedValue, path);
}
这是我的.cs代码
public void saveMoreImage( string StrName, string LetterCreatDate, string ProjectID , string path)
{
conn.Open();
SqlCommand cmd1 = new SqlCommand("spinsertMoreImages", conn);
cmd1.CommandType = CommandType.StoredProcedure;
cmd1.Parameters.AddWithValue("@TrackerID", fID);
cmd1.Parameters.AddWithValue("@PhotoName", StrName);
cmd1.Parameters.AddWithValue("@CreateDate", LetterCreatDate);
cmd1.Parameters.AddWithValue("@ProjectID", ProjectID);
cmd1.Parameters.AddWithValue("@PhotoDynamicName", path);
cmd1.ExecuteNonQuery();
conn.Close();
}
这是@createDate和@ProjectID的一个问题,我们如何将这两个数据插入另一个具有相同跟踪ID的表中
由于