Last post Jun 01, 2019 04:24 PM by eldonlhale
May 30, 2019 10:13 PM|eldonlhale|LINK
I am looking for some help with a data entry screen I've built. The form will be used to add new records to an existing DB. With the form already built, I'm looking for some help with the code I need to commit (insert) the values from the form to the DB.
The DB is SQL SERVER.
I am currently using Web Forms with Entity Framework to build the app and I want the data entry form to be available from a link on the default page. I've looked at GridView and FormView as options, but they don't meet my needs. Admittedly I am new with
asp.net, c# and EntityFramework so I may not know how to best manipulate those views.
Can someone tell me the code I would need to use the form to add new records to the database?
I'm also open to suggestions of any easier/better methods.
May 31, 2019 05:53 AM|AddWeb Solution|LINK
Here Based on your description, I have no idea about your data entry screen fields or UI . But here i will suggest you some references with form examples to reach at your milestones. I hope this will help you.
Please refer the following links
May 31, 2019 07:51 AM|Yongqing Yu|LINK
According to your description, I suggest that you display the original data in the gridview, and add a FooterTemplate to the last column of data in the GridView to put the link on the default page.
Then create a RowsAdd.aspx page which is to enable you to entry data to the textbox controls in the form, and add a submit form button to store the input data.
You could get the input data in the onclick event of the button, and stores it in the corresponding database.
All information in the form is wrapped in <form></form>. Wrap all <input> boxes with <form> and when you click submit button, you will submit all <input>boxes wrapped by <form> to an address in the code behind.
You could refer to: https://www.w3schools.com/html/html_forms.asp
For more details , you could also refer to my code as below:
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="Id" DataSourceID="SqlDataSource1" ShowFooter="True">
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" SortExpression="Name" />
<asp:BoundField DataField="Gender" HeaderText="Gender" SortExpression="Gender" />
<asp:TemplateField HeaderText="Country" SortExpression="Country">
<asp:Label ID="Label1" runat="server" Text='<%# Bind("Country") %>'></asp:Label>
<asp:HyperLink ID="Add" runat="server"
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" SelectCommand="SELECT * FROM [Test]"></asp:SqlDataSource>
<form id="form1" runat="server">
<asp:TextBox ID="Name1" runat="server"></asp:TextBox>
<asp:TextBox ID="Gender1" runat="server"></asp:TextBox>
<asp:TextBox ID="Country1" runat="server"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Save"
RowsAdd code behind:
protected void Button1_Click(object sender, EventArgs e)
string Name = Name1.Text.ToString();
string Gender = Gender1.Text.ToString();
string Country = Country1.Text.ToString();
using (var conn = new SqlConnection())
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
var insertCommand = new SqlCommand("INSERT INTO [Test] (Name, Gender, Country) VALUES (@Name, @Gender, @Country); ", conn);
insertCommand.Parameters.Add(new SqlParameter("Name", Name));
insertCommand.Parameters.Add(new SqlParameter("Gender", Gender));
insertCommand.Parameters.Add(new SqlParameter("Country", Country));
catch (Exception ex)
The result of my work demo:
May 31, 2019 12:09 PM|yogyogi|LINK
Since you are using Entity Framework, Web Forms and SQL Server to design an entry form. Therefore I recommend you to consult this tutorial:
Jun 01, 2019 04:24 PM|eldonlhale|LINK
AddWeb, YongQing & YogYogi,
Thank you! These resources look very promising!! I will go over them and see what best applies. I appreciate the references, it's a tremendous help. This forum has been the best place for help. Thank you again!