Inserting data and image into SQL
-
:((Please help!! I working on a simple CMS. On the admin page I have a Textarea/(WSYWIG editor(HTMLAREA)) where the user can type the content of the page. Then on the same page I have a usercontrol to upload images in the database in table image. But when I click on teh upload button the page gets posted and I am not able to get the image id field from the new record in the pageload event when the page posts(that is how I can the HTMLcode of the content from the editor) to insert in the pagecontent table. Hope this makes sense. Basially what I need help is with inserting data into different tables but i need the primary key from the image table to insert as the foreign key in the pagecontent table. Thanks in advance and I would really appreciate if someone can help ASAP!!!!
-
:((Please help!! I working on a simple CMS. On the admin page I have a Textarea/(WSYWIG editor(HTMLAREA)) where the user can type the content of the page. Then on the same page I have a usercontrol to upload images in the database in table image. But when I click on teh upload button the page gets posted and I am not able to get the image id field from the new record in the pageload event when the page posts(that is how I can the HTMLcode of the content from the editor) to insert in the pagecontent table. Hope this makes sense. Basially what I need help is with inserting data into different tables but i need the primary key from the image table to insert as the foreign key in the pagecontent table. Thanks in advance and I would really appreciate if someone can help ASAP!!!!
You didn't provide what type of database you are using, so I can't provide you with syntax. But I will provide you with the logic you need. There is no need to perform the insert of the image record before the postback and the following record after the postback. You can perform both inserts prior to the postback. When you first submit the form, insert the image record into the database. You should return an output parameter containing the primary key of the newly added image record from the SQL code. Grab this value with your .NET code. Then perform an insert to the pagecontent table supplying the retrieved value as an input parameter. NOTE: You will probably want to (eventually) encompass both insert statements within a transaction so that they both succeed or both fail, but that is an entirely different discussion. Hope this helps. If not, supply some more information (i.e. .NET language C#/VB, database type SQL Server/Access/etc, database table structures, or post your code). Good luck. Ryan Bost http://www.sugarcoding.com
-
You didn't provide what type of database you are using, so I can't provide you with syntax. But I will provide you with the logic you need. There is no need to perform the insert of the image record before the postback and the following record after the postback. You can perform both inserts prior to the postback. When you first submit the form, insert the image record into the database. You should return an output parameter containing the primary key of the newly added image record from the SQL code. Grab this value with your .NET code. Then perform an insert to the pagecontent table supplying the retrieved value as an input parameter. NOTE: You will probably want to (eventually) encompass both insert statements within a transaction so that they both succeed or both fail, but that is an entirely different discussion. Hope this helps. If not, supply some more information (i.e. .NET language C#/VB, database type SQL Server/Access/etc, database table structures, or post your code). Good luck. Ryan Bost http://www.sugarcoding.com
Thanks for replying Ryan, I have tried many different ways of making this work but to no avail. I will appreciate if you can take alook at my code and help me with the syntax. I am using vb.net and SQL server database. And if you know of a better wsywig editor please let me know.