啥也不说了,刚刚研究出来滴~~~贴码:
/// <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;
Austin Liu 刘恒辉
Project Manager and Software Designer E-Mail:lzhdim@163.com Blog:https://lzhdim.cnblogs.com 欢迎收藏和转载此博客中的博文,但是请注明出处,给笔者一个与大家交流的空间。谢谢大家。 |