Click here to Skip to main content
15,889,651 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Query to insert data in a table from two different forms ? using id stored in session
i mean can we use like .... insert into table1() values () where userid=session[userid] ??
Posted
Comments
Bh@gyesh 10-Apr-14 4:56am    
Hi,
can you please more elaborate with your question?
One thing you can do, you can save one form value in session or pass with querystring to another form. then on final form you can insert records in two tables.

OP Wrote:
can we use like .... insert into table1() values () where userid=session[userid]

No.You cannot use like that. Insert statement have no where clause
 
Share this answer
 
Comments
Nirav Prabtani 10-Apr-14 5:05am    
sorry by mistake i've voted +1
now how can i upvote it???
Tom Marvolo Riddle 10-Apr-14 5:06am    
yup press ctrl+ f5 and you can revote it
Nirav Prabtani 10-Apr-14 5:17am    
I have done it.... :)
Tom Marvolo Riddle 10-Apr-14 5:18am    
Thank you Nirav Prabtani
No you can not user where clause whith insert statement ,
If you have to set data to perticuler ID then you can use
Update sql query like this.... :) :)

SQL
UPDATE Table Set ColumnName=@ColumnData,ColumnName=@ColumnData2.... where userid=Session[userid]
 
Share this answer
 
Comments
jayraj86 10-Apr-14 9:29am    
Thanks a lot. I never thought about that :)
jayraj86 10-Apr-14 9:33am    
one other problem i m stuck at right now, can you sort it out ?
here is the link http://www.codeproject.com/Questions/756411/In-Asp-Net-Csharp-I-Have-Four-Dropdownlist-And-I-W
The INSERT INTO statement is used to insert new records in a table, there is no need for WHERE clause. Refer: Using-Parameterized-queries-to-prevent-SQL-Injection-Attacks-in-SQL-Server.aspx[^]
An example:
strQuery = "insert into tablename(userID, userName)values(@userID, @userName)";
cmd = new SqlCommand(strQuery);
cmd.Parameters.AddWithValue("@userID", Session["userid"]);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900