Solved

ASP.Net How to display data from a textbox

Posted on 2015-01-22
3
170 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 75

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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

785 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