Solved

ASP.Net How to display data from a textbox

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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 Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

713 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