Sunday, February 19, 2012

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.

No comments:

Post a Comment