Showing posts with label boxes. Show all posts
Showing posts with label boxes. Show all posts

Sunday, February 19, 2012

Inserting records and displaying them

Before I start driving myself nuts, I'd like to make sure my approach is correct.

I want to create a simple job posting board.
I have a text boxes for company name, email, job title, and job description, and a submit button.
I created a table in my database called "JobPostings", with columns called "CoName", "CoEmail", "JobTitle", and "JobDesc"

When someone fills out the fields and clicks submit, it will insert the new records.

So,
1. Is this the correct approach so far?

2. What is the best way to display the job listings? A grid view?

3. At submit time, how can I include that day's date?

4. How can I get the records in the database to delete after 90 days?

Thanks.

1. If it did what you want, it's correct to youSmile

2. You can try SqlDataSource+GridView, see

3. You can add a datetime column (e.g. CreateDate) to the table, whose default value is getdate() so that when a new record being inserted you don't need to specify date for the column:

ALTER TABLE mytable ADD CreateDate DATETIME DEFAULT GetDate()

4. You can use such command to delete records older than 90 days:

DELETE FROM mytable WHERE DATEDIFF(d,CreateDate,GETDATE())>90

Inserting Question

Hey Guys:

I got a quick question, I am trying to insert five text boxes information into a sql database. I can easily do this by leaving the textboxes blank, and having a user enter a value then simply inserting the value into the database.

My issues is that I am creating a review page. The first page users will enter in values into a text box, then the second page(where the insert statement is located) displays the results, along with another query to find the user_id from the system.user. I keep getting an error stating that the viewstate is unknown, or something along those lines.

Basicly I think my error comes because I am passing the variables across the pages, then calling them, and then inserting them into the textbox values. I'm just wondering if you guys could tell me how to insert values from the past page, a tutorial would be great, or a site!

Oh: SqlServer, Asp.net, VB.net

Thanks,
Brian SierakowskiHeres the code I have before I do any of the INSERT statment stuff. Basicly I am going to put a button on the bottom of the page the when clicked will insert the Auction_id, User_id, Bid_date, Bid_amount, and Bid_status into the database.

Everything but the user_id is declared at the top, I then do a sql search to find the user_id based on the user.system.identity, and display it.

I am just completely lost here, I'm not sure If I need to create a dataset, or if I can just insert the information using an sql INSERT statement using the declared varables as the top, and the user_id, I may also be able to do a lookup for the user_is, and the insert in two sql statements, not sure.

Oh the table where the information will be submitted is simply a lookup table, the values are integers being inserted are related to other tables.


<%@. Page Language="vb" %>
<%@. Reference Page="placebid.aspx" %>
<%@. Import Namespace="System.Data" %>
<%@. Import Namespace="System.Data.SqlClient" %>
<%@. Import Namespace="System.Web.Security" %
<script runat="server">
Dim fp As FirstPageClass
Dim sUser As String
Dim DateSubmitted As String
Dim AmountSubmitted As String
Dim StatusSubmitted As String

Sub Page_Load()
If Not IsPostBack Then
fp = CType(Context.Handler, FirstPageClass)
End If

sUser=Page.User.Identity.Name
DateSubmitted = DateTime.Now
AmountSubmitted = fp.Bid
StatusSubmitted = 1

Dim myDS As New DataSet()

Dim ConnStr As String
ConnStr = "CONNECTION STRING" 'changed by moderator due to presence of password -- thanks KraGiE

Dim SQLSelect As String
SQLSelect = "SELECT * FROM users WHERE users.username = '"& sUser &"' ;"

Dim mySqlConn As New SqlConnection(ConnStr)
Dim mySqlDA As New SqlDataAdapter(SQLSelect, ConnStr)

mySqlDA.Fill(myDS)

auction2.DataSource = myDS.Tables(0).DefaultView
auction2.Databind()

End Sub
</script
<FORM runat="server" ID="Form1">
Hello <%=fp.UserName%> -- <%=fp.Bid%
<asp:datalist id="auction2" runat="server" Width="500" ShowFooter="False" ShowHeader="False" BorderWidth="0px" CellSpacing="5" repeatcolumns="1" gridlines="none" cellpadding="5">
<ItemTemplate>
<table cellspacing="1" cellpadding="0" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FFFFFF" class="maintext">
Username:<%# DataBinder.Eval(Container.DataItem, "username")%>
<br>
User ID: <%# DataBinder.Eval(Container.DataItem, "user_id")%>
<br>
</td>
</tr>
</table>
</Item Template>
</asp:datalist>
</FORM>

|||I don't really see what you're doing with fp = CType(Context.Handler, FirstPageClass), and that may be why it's not working. However, I was planning on emailing you, but I guess you don't want that due to it not being in your profile.

I'd delete that connection string as soon as you get this, and in the next post, just kindly leave a note starting with *** NOTE TO MODERATOR ***, and let them know the second post on this thread requires edits due to security purposes. Either way, I'd suggest changing the password as soon as you can.