C # compiling the SqlHelper class (3 ),
The following describes how to directly write a complete SqlHelper using a variable length parameter.
Add, delete, and modify
Public static int ExecuteNonQuery (string SQL, params Parameter [] parameters)
{
Using (SqlConnection conn = new SqlConnection (conStr ))
{
Conn. Open ();
Using (SqlCommand cmd = conn. CreateCommand ())
{
Cmd. CommandText = SQL;
Cmd. Parameters. AddRange (parameters );
Return cmd. ExecuteNonQuery ();
}
}
}
Query
Public static object ExecuteScalar (string SQL, params Parameter [] parameters)
{
Using (SqlConnection conn = new SqlConnection (conStr ))
{
Conn. Open ();
Using (SqlCommand cmd = conn. CreateCommand ())
{
Cmd. CommandText = SQL;
Cmd. Parameters. AddRange (parameters );
SqlDataAdapter adpter = new SqlDataAdapter (cmd );
DataSet data = new DataSet ();
Adapter. Fill (data );
Return data;
}
}
}