Data retrieval from TextBox and insert in to database

Tags:
ASP.NET
ASP.NET 3.5
C#
C# 2008
Database connectivity
Database programming
SQL connectivity
SQL Server 2005
SQL Server 2005 connectivity
TextBox
Hi i am learning c#2008 and asp.net3.5. I want to get data from my textbox control and insert it in database so i cant find any source code or presentation so please tell me how to do it or give me site address where i can find this Thanks
ASKED: November 10, 2008  10:33 AM
UPDATED: April 15, 2010  5:41 AM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Here is an example:

<pre>private void btnNext_Click(object sender, RoutedEventArgs e)
{
string first = txtFirst.Text;
string last = txtLast.Text;
string nick = txtNick.Text;

if (first == “” || last == “” || nick == “”)
{
MessageBox.Show(“Please ensure all fields are entered”, “Error”, MessageBoxButton.OK, MessageBoxImage.Error);
}
else
{
System.Data.SqlClient.SqlConnection dataConnection = new SqlConnection();
dataConnection.ConnectionString =
@”Data Source=SW-DEV-PROWLAND\SQLEXPRESS08;Initial Catalog=playerDb;User ID=*****;Password=********;Pooling=False”;

System.Data.SqlClient.SqlCommand dataCommand = new SqlCommand();
dataCommand.Connection = dataConnection;

//tell the compiler and database that we’re using parameters (thus the @first, @last, @nick)
dataCommand.CommandText = (“INSERT playerDetails (FirstName, LastName, NickName) VALUES (@first, @last, @nick)”);

//add our parameters to our command object
dataCommand.Parameters.AddWithValue(“@first”, first);
dataCommand.Parameters.AddWithValue(“@last”, last);
dataCommand.Parameters.AddWithValue(“@nick”, nick);

dataConnection.Open();
dataCommand.ExecuteNonQuery();
dataConnection.Close();
}
} </pre>

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following