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:
<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dt d">
<script runat="server">
private void InsertRecord(ob ject source, EventArgs e)
{
AccessDataSourc e1.Insert();
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitl ed 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="btnInsertRe cord" runat="server" Style="z-index: 100; left: 273px;
position: absolute; top: 102px" Text="Insert Record" OnClick="Insert Record" Width="117px" />
<asp:TextBox ID="Surname" runat="server"> </asp:TextBox>
<asp:TextBox ID="Course" runat="server"> </asp:TextBox>
<asp:AccessData Source ID="AccessDataS ource1" 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] = ?">
<DeleteParamete rs>
<asp:Paramete r Name="ID" Type="String" />
</DeleteParameter s>
<UpdateParamete rs>
<asp:Paramete r Name="Firstname " Type="String" />
<asp:Paramete r Name="Surname" Type="String" />
<asp:Paramete r Name="Course" Type="String" />
<asp:Paramete r Name="ID" Type="String" />
</UpdateParameter s>
<InsertParamete rs>
<asp:Paramete r Name="ID" Type="String" />
<asp:Paramete r Name="Firstname " Type="String" />
<asp:Paramete r Name="Surname" Type="String" />
<asp:Paramete r Name="Course" Type="String" />
</InsertParameter s>
</asp:AccessDataS ource>
</div>
</form>
</body>
</html>