Microsoft.ApplicationBlocks使用心得

查询返回单行ID
string sql = string.Format("select id from account where name='{0}' and password='{1}'", name, password);
object AID = SqlHelper.ExecuteScalar(CON_STR, CommandType.Text, sql);
int ID = Convert.ToInt32(AID);


插入返回新记录ID
string sql = string.Format("insert into account (name ,password) values ('{0}', '{1}'); Select CAST(@@Identity AS INTEGER)", account.Name, account.Password);
object AID = SqlHelper.ExecuteScalar(CON_STR, CommandType.Text, sql );
int id = Convert.ToInt32(AID);


查询返回多行记录
string sql = string.Format("select id, name, password from account where id={0}", id);
SqlDataReader dr 
= SqlHelper.ExecuteReader(CON_STR, CommandType.Text, sql);
if (dr.Read()) 
{
    acc 
=  new Account(dr.GetInt32(0), dr.GetString(1), dr.GetString(2));
}

dr.Close();
posted @ 2004-10-19 12:18  dannyr|一个都不能少!  阅读(2106)  评论(4编辑  收藏  举报