ASP.Net How to display data from a textbox

I am just learning .net and I would like to know how to write a simple program to get the data that was inputted into a textbox and save it to an SQL DB.

Can you help?
huerita37Asked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
LordWabbitConnect With a Mentor Commented:
Ok, bare bones, simple as spit webforms text box to save into a database using simple ado.net.  Bear in mind that nowadays the entity framework is the preferred way to work with a database, but that would make this simple task seem a lot more complicated.  
The web form markup
        <asp:TextBox runat="server" id="txtSaveThis"></asp:TextBox><br />
        <asp:Button runat="server" ID="btnSave" Text="Save" OnClick="btnSave_Click" />

Open in new window


and the code behind

        Dim con As New System.Data.SqlClient.SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("EETest").ConnectionString)
        con.Open()
        Dim sql As String = "INSERT INTO SaveText (Text) VALUES (@Text)"
        Dim command As New System.Data.SqlClient.SqlCommand(sql, con)
        command.Parameters.AddWithValue("@Text", txtSaveThis.Text)
        command.ExecuteNonQuery()

Open in new window


If you have an issue with the ConfigurationManager you will need to add a reference to System.Configuration.
0
 
käµfm³d 👽Commented:
Have you searched for any tutorials on the subject? There are countless examples on the subject. Furthermore, ASP.NET is a broad term these days. There is Web Forms and MVC. Which are you using?
0
 
huerita37Author Commented:
I actually don't know. Just trying to learn.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.