I'm trying to add new records to my database using 4 textboxes, one for each field in my databases table. I've got ID, Firstname, Surname and Course.
But I can't figure out at all how to link whats Inputted into the textboxes to be added as a new record to my database when the "Insert Record" button is pushed.., i've spent nearly 2 hours searching the internet for tutorials and people asking similar questions but I can't find anything that works.
I think the solution might be in this line of code:
InsertCommand="INSERT INTO [Data1] ([ID], [Firstname], [Surname], [Course]) VALUES ()"I've tried putting the ID's of my textboses in the "VALUES ()" part..
(e.g. VALUES (ID.Text, Firstname.Text, Surname.Text, Course.Text)But that doesn't seem to work, I need the values to be what has been inputted into my textboxes, but I'm not sure what the correct way to do that is or what I need to write between the brackets.
My textboxes ID's are ID, Firstname, Surname and Course.
Heres a screenshot of the page, to make it easier to understand what I'm talking about:
Fullcode for the page is:CODE
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
private void InsertRecord(object source, EventArgs e)
{
AccessDataSource1.Insert();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:TextBox ID="ID" runat="server"></asp:TextBox>
<asp:TextBox ID="Firstname" runat="server"></asp:TextBox>
<asp:Button ID="btnInsertRecord" runat="server" Style="z-index: 100; left: 273px;
position: absolute; top: 102px" Text="Insert Record" OnClick="InsertRecord" Width="117px" />
<asp:TextBox ID="Surname" runat="server"></asp:TextBox>
<asp:TextBox ID="Course" runat="server"></asp:TextBox>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/App_Data/unidata.mdb"
DeleteCommand="DELETE FROM [Data1] WHERE [ID] = ?" InsertCommand="INSERT INTO [Data1] ([ID], [Firstname], [Surname], [Course]) VALUES ()"
SelectCommand="SELECT * FROM [Data1]" UpdateCommand="UPDATE [Data1] SET [Firstname] = ?, [Surname] = ?, [Course] = ? WHERE [ID] = ?">
<DeleteParameters>
<asp:Parameter Name="ID" Type="String" />
</DeleteParameters>
<UpdateParameters>
<asp:Parameter Name="Firstname" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
<asp:Parameter Name="Course" Type="String" />
<asp:Parameter Name="ID" Type="String" />
</UpdateParameters>
<InsertParameters>
<asp:Parameter Name="ID" Type="String" />
<asp:Parameter Name="Firstname" Type="String" />
<asp:Parameter Name="Surname" Type="String" />
<asp:Parameter Name="Course" Type="String" />
</InsertParameters>
</asp:AccessDataSource>
</div>
</form>
</body>
</html>