?
Solved

ASP.Net How to display data from a textbox

Posted on 2015-01-22
3
Medium Priority
?
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 2000 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

Percona Live Europe 2017 | Sep 25 - 27, 2017

The Percona Live Open Source Database Conference Europe 2017 is the premier event for the diverse and active European open source database community, as well as businesses that develop and use open source database software.

Question has a verified solution.

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

In this post we will learn different types of Android Layout and some basics of an Android App.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
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 the fundamental information of how to create a table.

777 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