Where can I find some reference materials on ASP.net database submission forms
I am new to asp.net, looking for a tutorial that will teach me how to make a web registration form with many textboxes, dropdowns etc and subm开发者_Go百科it this information into the database tables on the user pressing the submit button.
I've searched but so far come up with nothing.
If you look at the data access part of asp.net/learn there's a ton of tutorials specifically surrounding data access through asp.net, although from what you've posted I suspect that this is "over-complicated" for what you're after.
At its simplest what you want to do is have your aspx page, lets call it default.aspx and have the following in it:
<asp:TextBox runat="server" ID="myTextBox">
</asp:TextBox>
<asp:Button runat="server" ID="myButton" OnClick="myButton_OnClick" Text="Click to save" />
Now in your codebehind file (the .aspx.cs file) you'll want to have an event handler for the Click event of myButton
protected void myButton_Click(object sender, EventArgs e)
{
var myConnectionString = "Connection String goes here";
using (SqlConnection conn = new SqlConnection(myConnectionString))
{
using (SqlCommand cmd = new SqlCommand("INSERT INTO dbo.mytable (fieldName) VALUES (@value1)", conn))
{
cmd.Parameters.Add(new SqlParameter("@value1", myTextBox.Text));
cmd.ExecuteNonQuery();
}
}
}
The example code above, for doing the database work, is very rudimentary and I strongly suggest you read some of the tutorials on asp.net/learn and elsewhere on the net (perhaps even the msdn documentation for SqlCommand, SqlParameter and SqlConnection) to familiarise yourself with what they are and how they work.
Go on this page and you will find some nice video tutorial where you can pick some concepts also
added:
My advice to you would be not to judge good answers as asp.net by author who post them, also if the answer does not help you should contribute and tell us what site does not contain what would be helpful to you.
best regards.
精彩评论