我建立一個迷你論壇網站..和我構建了幾個表。我需要幫助與sql和數據關係表
1)用戶 2)線程 3)評論 4)主題
我建立,將每次插入註釋功能的用戶將提交評論:
string saveComment = "INSERT INTO Comments(";
saveComment += " UsersID, ThreadsID, Date, Comments, CommentResponse";
saveComment += "Values('" + "','";// no idea what to insert in the UsersID
saveComment += "" + "','";// no idea what to insert in the ThreadsID
saveComment += DateTime.Now + "','";
saveComment += CommenttxtBox.Text + "','";
saveComment += commentResponseString + "')";
正如你可以看到這些字段具有UsersID和ThreadID,兩者都通過外鍵連接到comments表。 現在,每次用戶提交評論,我想我還需要插入到UsersID字段(這是評論表中的一個int,並且該字段在用戶表中增加1)。我如何插入評論,並通知其他表不要增加用戶ID 1.事實上,我希望它的用戶ID保持不變,爲每個用戶提交評論..
我該怎麼做?我需要插入到一個表中的幾個字段(註釋),但要告知其他表,它們實際上是提交評論的同一用戶。
注:我不知道任何VB,只有C#和我使用Visual Studio 2010 asp.net
努力瞭解這裏的問題,爲什麼插入到註釋表中對其他表有什麼影響? – iandayman 2011-05-13 11:42:44
因爲他們通過鏈接 – 2011-05-13 12:38:51