我正在制作一个简单的新闻系统,用户可以在其中写新闻故事,并添加一张照片。我如何从一张桌子上取得身份证件并放置在另一张桌子上?
我所知道的“逻辑”的背后是什么,我需要做的:
保存在数据库中的图像细节,并得到,当它被插入
保存的消息称,被使用的ID故事与图片ID一起我刚刚得到上述
我怎么能填充newsPicID
场tblNews与当PIC被插入到被使用的ID picID
字段在tblPic?
我的INNER JOIN会看起来像这样吗?
SELECT * FROM tblNews INNER JOIN picTable ON picTable.picID = newsTable.newsPicID
对于任何引用,这里是我当前的代码:
if (FileUpload1.PostedFile != null)
{
string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
// Save files to disk
FileUpload1.SaveAs(Server.MapPath("/images/admin/news/" + FileName));
// Add Entry to DataBase
String strConnString = System.Configuration.ConfigurationManager.ConnectionStrings["conString"].ConnectionString;
SqlConnection con = new SqlConnection(strConnString);
string strQuery = "insert into tblFiles (FileName, FilePath) values(@FileName, @FilePath); insert into tblNews (newsTitle, newsDate, newsSummmary, newsContent) values(@newsTitle, @newsDate, @newsSummmary, @newsContent)";
SqlCommand cmd = new SqlCommand(strQuery);
cmd.Parameters.AddWithValue("@FileName", FileName);
cmd.Parameters.AddWithValue("@FilePath", "/images/admin/news/" + FileName);
cmd.Parameters.AddWithValue("@newsTitle", txtnewstitle.Text);
cmd.Parameters.AddWithValue("@newsDate", txtnewsdate.Text);
cmd.Parameters.AddWithValue("@newsSummary", txtnewssummary.Text);
cmd.Parameters.AddWithValue("@newsContent", txtnewsmaincontent.Text);
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
try {
con.Open();
cmd.ExecuteNonQuery();
}
finally {
con.Close();
con.Dispose();
}
}
是picID标识字段? –
@Vicky_Thinking是的。 tblFiles中的picID和tblNews中的newsID是主要和标识 – cmp