啥也不说了,刚刚研究出来滴~~~贴码:
/// <summary>插入
/// 返回刚刚插入的ID
/// </summary>
/// <param name="groupname"></param>
/// <param name="gid"></param>
/// <returns></returns>
public bool Insert(string groupname, out string gid)
{
string sql = "insert into groupca(groupname) values(@groupname);select last_insert_rowid();";
helper.CreateCommand(sql);
helper.AddParameter("@groupname", groupname as object);
string res = helper.ExecuteScalar();
if (!string.IsNullOrEmpty(res))
{
gid = res;
return true;
}
else
{
gid = "0";
return false;
}
}
/// 返回刚刚插入的ID
/// </summary>
/// <param name="groupname"></param>
/// <param name="gid"></param>
/// <returns></returns>
public bool Insert(string groupname, out string gid)
{
string sql = "insert into groupca(groupname) values(@groupname);select last_insert_rowid();";
helper.CreateCommand(sql);
helper.AddParameter("@groupname", groupname as object);
string res = helper.ExecuteScalar();
if (!string.IsNullOrEmpty(res))
{
gid = res;
return true;
}
else
{
gid = "0";
return false;
}
}
上面的代码用到了自己之前创建的一个SQLITE数据库的操作类,当然,最主要的就是那一句语句了,其实select last_insert_rowid();也就相当于MSSQL中的select @@identity;