How to connect database in asp.net?
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
arjunan selvam5 reputationPosted Sep 24, 2012, 2:11 AM EDT
SqlCommand command = new SqlCommand();
connection.ConnectionString = @"Data Source=.\SQLEXPRESS;" +
"Initial Catalog=University;Integrated Security=SSPI";
command.Connection = connection;
command.CommandText = "INSERT INTO Employees " +
"(FirstName) VALUES " +
"(@FirstName)";
command.Parameters.AddWithValue("@FirstName", firstNameTextBox.Text);
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (SqlException ex)
{
}
finally
{
connection.Close();
}
Add Textbox and button in the webform.Copy the above code into button_clickEvent.Employee table should be there in your database.
VulpesRank #55 · 29.2K reputationPosted Sep 21, 2012, 3:59 AM EDT
http://www.connectionstrings.com/
Pranjal Mishra58 reputationPosted Sep 24, 2012, 7:53 AM EDT