博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
使用sqlite保存数据返回主键
阅读量:7072 次
发布时间:2019-06-28

本文共 1700 字,大约阅读时间需要 5 分钟。

///         /// 返回insert后的主键值        ///         ///         ///         /// 
public static int ExecuteSql(string SQLString, List
para) { using (SQLiteConnection connection = GetSQLiteConnection()) { using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection)) { try { connection.Open(); if (para!=null) { foreach (SQLiteParameter p in para) { cmd.Parameters.Add(p); } } int rows = 0; if (SQLString.IndexOf("insert") != -1) rows = Convert.ToInt32(cmd.ExecuteScalar()); else rows = cmd.ExecuteNonQuery(); return rows; } catch (SQLiteException e) { connection.Close(); throw e; } } } }

注意:要在同一个连接下可以

string sql = "insert into ims_tbl_HotelInfo(HotelId,HotelName,HotelTelephone,HotelAddress,Remark,KId,Vip,XId,YId,BId,CId,DId,EId,FId,HId) values('" + hotelId + "','" + hotelName + "','" + hotalTelephone + "','" + hotalAddress + "','" + hremark + "',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ')";                            int result = SQLiteDBHelper.ExecuteSql(sql + ";select last_insert_rowid();", null);//返回主键

 

转载于:https://www.cnblogs.com/robinblogs/p/3721803.html

你可能感兴趣的文章
关于逻辑运算符书写效率问题 和数组 处理问题
查看>>
【web开发学习笔记】Structs2 Result学习笔记(一)简介
查看>>
android studio中取消关联git
查看>>
Mysql的共享锁和排他锁(转载)
查看>>
Preemption Context Switches 和 Synchronization Context Switches
查看>>
UVA 10405 Longest Common Subsequence (动态规划 LCS)
查看>>
CURL常用命令
查看>>
阿里巴巴技术团队博客
查看>>
java 单例模式
查看>>
IIS8 使用FastCGI配置PHP环境支持 过程详解
查看>>
互联网TCP/IP五层模型(一)
查看>>
ftrace 简介【转】
查看>>
用H5中的Canvas等技术制作海报
查看>>
python正则表达式匹配时间和IP地址
查看>>
【三石jQuery视频教程】01.图片循环展示
查看>>
matlab std函数 用法及实例
查看>>
【linux shell系列--1】crontab命令
查看>>
电脑运行 apk
查看>>
PHPExcel读取Excel文件
查看>>
最近写的一个Win8的看漫画程序
查看>>