Using System;
Using System.Data;
Using System.Data.SqlClient;
Using System.Configuration;
Namespace Admin.commonclass
{
<summary>
The class--opendb that links the database
</summary>
public class Opendb
{
To get a string of linked databases
private string Strjet = configurationsettings.appsettings["strconn"];
Public Opendb ()
{
//
TODO: Add constructor logic here
//
}
#region Get DataSet
<summary>
Get a DataSet, format: GetDataSet (query field, query table, condition field, conditional symbol, condition value)
</summary>
<param name= "Strzdname" ></param>
<param name= "strTableName" ></param>
<param name= "Strwherevalue" ></param>
<returns></returns>
Public DataSet GetDataSet (string strzdname,string strtablename,string strwherevalue)
{
To create an object that links a database
SqlConnection myconn = new SqlConnection (Strjet);
Creating adapter Objects
SqlDataAdapter myadapter = new SqlDataAdapter ("Sp_getdataset", myconn);
Indicate as stored procedure
MyAdapter.SelectCommand.CommandType = CommandType.StoredProcedure;
Assigns a value to a stored procedure's STRZD variable, which indicates the query field.
MYADAPTER.SELECTCOMMAND.PARAMETERS.ADD ("@ZDName", SqlDbType.Char). Value = Strzdname;
Assigns a value to a stored procedure's Fromwhere variable, which indicates the query table.
MYADAPTER.SELECTCOMMAND.PARAMETERS.ADD ("@TableName", SqlDbType.Char). Value = strTableName;
Assigns a value to a stored procedure's Wherevalue variable, which indicates the query condition.
MYADAPTER.SELECTCOMMAND.PARAMETERS.ADD ("@WhereValue", SqlDbType.Char). Value = Strwherevalue;
Creating a DataSet Object
DataSet ds = new DataSet ();
Populating data
Myadapter.fill (ds, "Strfromwhere");
Returns a DataSet
return DS;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service