问题
I am using Telerik controls in Visual Studio 2008, in RadGrid. I create a PopUp windows includes all the TextBoxes and controls that I need to use in database but how can I declare a function in order to insert, update and delete ? And where!?
回答1:
You can use Data Access Layer for Definition of the the function to send the request to database
If you want to use SQL Server. Following is the code.
using (System.Data.SqlClient.SqlConnection con = new SqlConnection("YourConnection string")) {
con.Open();
SqlCommand cmd = new SqlCommand();
string expression = "Parameter value";
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Your Stored Procedure";
cmd.Parameters.Add("Your Parameter Name",
SqlDbType.VarChar).Value = expression;
cmd.Connection = con;
using (IDataReader dr = cmd.ExecuteReader())
{
if (dr.Read())
{
}
}
}
You can also use Microsoft Enterprise Library
You can Use Business Logic Layer to call the database layer function and also can perform validations before sending the data to Presentation Layer
Finally, You can call the Business Logic Layer objects in your Presentation layer
来源:https://stackoverflow.com/questions/6149472/telerikradgrid-how-to-insert-update-and-delete-into-sql-database