Solved

ASP.Net How to display data from a textbox

Posted on 2015-01-22
3
162 Views
Last Modified: 2015-01-29
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?
0
Comment
Question by:huerita37
3 Comments
 
LVL 74

Expert Comment

by:käµfm³d 👽
ID: 40565820
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
 

Author Comment

by:huerita37
ID: 40565839
I actually don't know. Just trying to learn.
0
 
LVL 11

Accepted Solution

by:
LordWabbit earned 500 total points
ID: 40565917
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

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Whether you've completed a degree in computer sciences or you're a self-taught programmer, writing your first lines of code in the real world is always a challenge. Here are some of the most common pitfalls for new programmers.
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now