开发者

SQL syntax, and c# table entry into database

I have two problems

  1. mySql snytax
  2. Inserting data from asp Table1 control

I have two tables User (which has UserID=1 (auto increment)) and WallPostings which has a field Wallpostings (not to confuse the two as one has capital P)

I would like to make a join so Wallpostings will know which userid its refering to and then insert the data from my Table1 control

Tables:

------------------
User
------------------
UserID (pk, AI)
Name
DOB
Location 
etc

-------------------
WallPostings
-------------------
UserID (pk)
Wallpostings 

has a one to one relationship for the tables

OdbcCommand cmd = new OdbcCommand("INSERT INTO WallPostings (Wallpostings) VALUES ('"+ Table1 +"')", cn);
OdbcDataReader reader = cmd.ExecuteRead开发者_运维知识库er();

Unsure how to make the join so the same userid thats set in my User table is the same in WallPosting table?


If you haven't already, you should have UserID in WallPostings be a foreign key of the User table so that it doesn't allow UserID's that don't exist there to enforce referential integrity.

Then in your code you don't need a join, you just need to know what the userID is when inserting the wall posting. So that you have:

insert into WallPostings
(userID, WallPosting)
values
(1, 'data goes here')

Assumedly the user is logged into the site in some fashion so that you know what their userID is when posting or making this data modification.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜