Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Insert new record in Access DB from aspx page

Status
Not open for further replies.

ajap99

Programmer
Dec 9, 2004
18
GB
I am using a datalist to display one entry in Access DB.
I want to enter new values into the textboxes on datalist and hit a submit button to insert new record in DB
I can do this when with the following code

strInsert = "INSERT INTO Bookings (StartDate, NoWeeks, Available) VALUES ( '09/09/1999', '3', '1')"

But I want to read the values from the asp text boxes.
Below is the asp textbox entries in the HTML on the page


<asp:TextBox id="tbstartDate" Text='<%# DataBinder.Eval(Container.DataItem, "StartDate") %>' Font-Size="Medium" runat="server" Width="73px" Font-Bold="True"></asp:TextBox>

<asp:TextBox id="tbNoWeeks" Text='<%# DataBinder.Eval(Container.DataItem, "NoWeeks") %>' Font-Size="Medium" runat="server" Width="73px" Font-Bold="True"></asp:TextBox>

<asp:TextBox id="tbAvailable" Text='<%# DataBinder.Eval(Container.DataItem, "Available") %>' Font-Size="Medium" runat="server" Width="73px" Font-Bold="True"></asp:TextBox>

How can I read the values entered into the textboxes into the 'INSERT' statement
 
Code:
strInsert = "INSERT INTO Bookings (StartDate, NoWeeks, Available) VALUES ( '" & tbstartDate.Text & "', '" & tbNoWeeks.Text & "', '" & tbAvailable.Text & "')"

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
When I use that code the following Compiler error Message is displayed

BC30451:name 'tbStartDate' is not declared

 
If you are using VS there should be a line within the "Web Form Designer Generated Code" section that looks like:
Code:
Protected WithEvents tbStartDate As System.Web.UI.WebControls.TextBox
If you are not using VS, you may have to add the line yourself.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
Oops - I just read that the Textboxes are in a DataList. Ignore that last post - you will have to use the FindControl method within your DataList to find the Textboxes.

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
The following message is displayed

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object

Fails at
strInsert = "INSERT INTO Bookings (StartDate) VALUES ( '" & tbstartDate.Text & "')"

I am just using webmatrix to compile code

I put the Protected WithEvents etc just under where I Dim connection to database - Is this OK
 
How would I use the find control method ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top