I am trying to insert names (string) in to a test database (sqlce). Basically, user will type in name in the textbox (input_box) and click on “Insert Button”. Upon click of the button, a call is made to “submit” function. I want the text from the textbox to be used as the parameter for insertcommand. I don’t get any error while running it. But when I check the data in the table, only “null” is inserted. I am trying to learn asp.net. Any help would be appreciated. Thank you.
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server"><title>Test run</title></head>
<script language="C#" runat = "server">
void Submit(object o, EventArgs e)
{
SqlDataSource1.Insert();
}
</script>
<body style="height: 395px">
<form id="form1" runat="server">
<asp:TextBox ID="Input_box" runat="server"></asp:TextBox>
<asp:Button ID="Insert_button" runat="server" Text=" Insert Button" OnClick = "Submit"/>
<asp:SqlDataSource
ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
InsertCommand="INSERT INTO Incident_Table(Assignee) VALUES (@assignee)"
ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>"
SelectCommand="SELECT Assignee FROM Incident_Table">
<InsertParameters>
<asp:FormParameter Name="assignee" FormField ="name"/>
</InsertParameters>
</asp:SqlDataSource>
</form>
</body>
</html>
you should replace this:
with: