Skip to content

C# DBHelper ORM Paging Transaction, MySQL MsSQL Access Oracle

Notifications You must be signed in to change notification settings

catcto/DBHelper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 

Repository files navigation

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();   
}

About

C# DBHelper ORM Paging Transaction, MySQL MsSQL Access Oracle

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages