how to connect database in asp.net?
how to connect database in asp.net?
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
arjunan selvamPosted Sep 24, 2012, 6:11 AM
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.
Pranjal MishraPosted Sep 24, 2012, 11:53 AM
VulpesPosted Sep 21, 2012, 7:59 AM
http://www.connectionstrings.com/