Giter VIP home page Giter VIP logo

dbhelper's Introduction

DbHelper

using Cat.Database;

web.config

<connectionStrings>
	<add name="ConnectionString" connectionString="server=.,1791;uid=xxx;pwd=xxx;database=pubs;trusted_connection=no;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient"/>
	<!--<add name="ConnectionString" connectionString="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=|DataDirectory|d_b.mdb" providerName="System.Data.OleDb"/>-->
</connectionStrings>

Usage

DbHelper db = new DbHelper();

Repeater1.DataSource = db.GetDataTable("select * from [jobs]");
Repeater1.DataBind();

SqlParameter par = new SqlParameter("@job_id", 1);
msg.Text = db.ExecuteScalar<string>("select job_desc from jobs where job_id=@job_id", par);

Paging

DbPager pager = new DbPager();
pager.field = "*";
pager.tableName = "jobs";
pager.primaryKey = "job_id";
pager.orderSql = "job_id desc";
//pager.appendSql = "left join jobs on jobs.job_id=employee.job_id";
pager.pagerSize = Pager1.PageSize;
pager.pagerIndex = Pager1.CurPage;
//pager.kind = DbPagerKind.TableVar;
Repeater1.DataSource = pager.GetData();
Pager1.RecordCount = pager.pagerCount;
Repeater1.DataBind();

Insert

DbInsert insert = new DbInsert();
insert.Add("job_desc", TextBox1.Text);
insert.Add("min_lvl", TextBox2.Text);
insert.Add("max_lvl", TextBox2.Text);
insert.Execute("jobs");

Update

DbUpdate update = new DbUpdate();
update.Add("max_lvl", TextBox2.Text);
SqlParameter par = new SqlParameter("@job_id", 1);
update.Execute("jobs", "where job_id=@job_id", par);

Transaction

DbHelper db = new DbHelper();
db.BeginTransaction();
try
{
	db.ExecuteNonQuery('sql...1');
	db.ExecuteNonQuery('sql...2');
	int a = 0;
    int b = 1 / a; //exception code
	db.ExecuteNonQuery('sql...3');
    db.CommitTransaction();
}
catch (Exception)
{
	db.RollbackTransaction();   
}

dbhelper's People

Contributors

catcto avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.