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