How to insert
How to update
How to delete
with microsoft visual studio asp.net application with microsoft sql server.
Thanks a lot for your help
Loading
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.
Vincent Maverick DuranoPosted Apr 27, 2015, 9:35 AM
There are many ways to do that in ASPNET depending if you are in MVC or WebForms
Using WebForms:
Here's a basic example how to insert data to database using ADO.NET: Creating a Simple Registration Form
Here's one example that uses LINQ to SQL: Inserting Data to Database using LINQ to SQL
Here's an example using Entity Framework: Inserting Data to Database using EF
Finally here's an example using a StoredProcedure with ADO.NET:
private void InsertInfo(){
using(SqlConnection connection = new SqlConnection("YOUR CONNECTION STRING HERE")){
connection.Open();
using(SqlCommand sqlCmd = new SqlCommand("YourStoredProcedureName", connection)){
sqlCmd.CommandType = CommandType.StoredProcedure;
sqlCmd.Parameters.AddWithValue("@Param1", "What ever value here");
sqlCmd.Parameters.AddWithValue("@Param2", TextBox1.Text);
sqlCmd.Parameters.AddWithValue("@Param3", TextBox2.Text);
sqlCmd.Parameters.AddWithValue("@Param4", TheUserIDValueThatYouWantToPassHere);
sqlCmd.ExecuteNonQuery();
}
}
}
protected void Button1_Click(object sender, EventArgs e){
//you may have to do some input validations here before calling the method insert
InsertInfo();
}
Edit,Update Delete:
http://geekswithblogs.net/dotNETvinz/archive/2010/05/05/editing-updating-and-deleting-data-in-the-form-using-linq.aspx
Using MVC:
Tom MohanPosted Apr 27, 2015, 2:18 AM
Are you using asp.net mvc or asp.net ? Search for CURD(Create Update Read Delete) operation in google. You will get lot of nice articles there :)
CURD with asp.net mvc and EF
http://www.asp.net/mvc/overview/older-versions/getting-started-with-ef-5-using-mvc-4/implementing-basic-crud-functionality-with-the-entity-framework-in-asp-net-mvc-application