A not-so-common data management class

Source: Internet
Author: User
Data public class Dbmanage
{
Public Dbmanage ()
{
//
TODO: Add constructor logic here
//
}
Public SqlConnection getconnection ()//Establish a database connection
{
SqlConnection cn=new SqlConnection ();
cn. connectionstring=system.configuration.configurationsettings.appsettings["Conn"];
cn. Open ();
return CN;
}
public void Delid (int intId, String strtable,sqlconnection cn)
{
SqlCommand deletecmd=new SqlCommand ("Delete from" +strtable+ "where id=" +INTID,CN);
Deletecmd.executenonquery ();
}
public void ExecuteSQL (String strsql,sqlconnection cn)//Execute SQL command with no return value
{
SqlCommand executecmd=new SqlCommand (STRSQL,CN);
Executecmd.executenonquery ();
Executecmd.dispose ();
}

public void Updatetb (string strtbname, String strfieldsname,string strvalue,int intId, SqlConnection cn)
{
SqlCommand updatecmd=new SqlCommand ("Update strtbname set" +strfieldsname+ "=" +strvalue+ "where id=" +intid.tostring (), CN);
Updatecmd.executenonquery ();
}
Public DataSet Fillds (string strSQL, SqlConnection cn)
{
SqlDataAdapter Filldsadapter=new SqlDataAdapter (STRSQL,CN);
Filldsadapter.selectcommand.commandtype=commandtype.text;
DataSet DS =new DataSet ();
Filldsadapter.fill (DS);
Filldsadapter.dispose ();
return DS;
}
Public DataSet Fillds (String strSQL, SqlConnection cn,string srctable)
{
SqlDataAdapter Filldsadapter=new SqlDataAdapter (STRSQL,CN);
Filldsadapter.selectcommand.commandtype=commandtype.text;
DataSet DS =new DataSet ();
Filldsadapter.fill (ds,srctable);
Filldsadapter.dispose ();
return DS;
}
public string GetString (String strsql,sqlconnection cn)/Get String
{
String Strgetstring= "";
SqlDataAdapter Filldsadapter=new SqlDataAdapter (STRSQL,CN);
Filldsadapter.selectcommand.commandtype=commandtype.text;
DataSet DS =new DataSet ();
Filldsadapter.fill (DS);
if (ds. Tables[0]. Rows.count==1)
{
Strgetstring=ds. Tables[0]. Rows[0][0]. ToString ();
}
Else
{
Strgetstring=null;
}
Filldsadapter.dispose ();
Ds. Dispose ();
return strgetstring;
}


}




Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.