开发者

How to insert data into the database using a textbox and logged in username

开发者 https://www.devze.com 2023-03-08 13:55 出处:网络
I am in the middle of a little project website where I have decided to create a basic messageboard that allows logged in users to write a comment (using a textbox) to which is added to the messageboar

I am in the middle of a little project website where I have decided to create a basic messageboard that allows logged in users to write a comment (using a textbox) to which is added to the messageboard database and then displayed using a gridview.

When a user writes a comment I also want to display their username to the post (showing they are the poster) as well as the date (which I have managed to do already using GetDate()).

So far I have this.

  1. I have a ASP.NETDB.MDF database which uses the .NET login functions to allow a user to sign up to my site and login. The default database creates IDNumber, Username etc fields.

  2. I have a messageboard database which has the following fields. ID, UserName, Time, Comment.

  3. 开发者_JS百科

So just to recap. When the user is logged in I want him to have the ability to go to the messageboard webpage and type in a comment using a textbox. When he clicks the submit button the message typed will be added to the database and then shown through the gridview. His username and time of post needs to automatically be added to the post (which can be determined through the user being logged in to a unique login account (how I do this I have no idea!).

Should I join the tables? (i.e Username (from login table) with Username from messageboard table? Is there a better way to go about all of this?

Sorry for being noobish..! I am kind of new at this.


You should join the tables if there is data in the "login" Table that you need to show next to the comment that does not exist in the "messageboard" table.

For Example if you want to show UserName,Message then you don't need a join because username is already stored in the messageboard table. However, if you want to display FullName,Message and FullName is in the login table and message is in the messageboard table, you will need a join.

Try looking for some examples of what you are trying to do on the internet. There should be a lot out there, I have seen quite a few blog style examples with ASP.NET MVC.

Good Luck

0

精彩评论

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

关注公众号