自增长的ID通过Sql如下可以获取:
select max(id) as id from recordinfo11
但是这个不是多线程安全的,可能是下一条插入的ID,但是我再应用层本来就是单线程处理的,所以就使用这个来获取了。
DBMysql dBMysql = new DBMysql();
dBMysql.ConnectDB("10.10.13.140", 3306, "root", "sa", "testdb");
RecordFileBlockt recordFileBlockt = new RecordFileBlockt()
{
item = new List<RecordFileBlockt_Item>(),
fileSize = "50",
fileEndTime = DateTime.Now.AddMinutes(0).ToString("yyyy-MM-dd HH:mm:ss"),
fileStartTime = DateTime.Now.AddMinutes(0).ToString("yyyy-MM-dd HH:mm:ss"),
};
recordFileBlockt.item.Add(new RecordFileBlockt_Item()
{
fileStartTime = recordFileBlockt.fileStartTime,
fileEndTime = recordFileBlockt.fileEndTime,
fileHead = "hiksss",
fileId = (0 * 2).ToString(),
filePath = "tttt.1"
});
recordFileBlockt.item.Add(new RecordFileBlockt_Item()
{
fileStartTime = recordFileBlockt.fileStartTime,
fileEndTime = recordFileBlockt.fileEndTime,
fileHead = "hiksss",
fileId = (0 * 2 + 1).ToString(),
filePath = "tttt.1"
});
string strSql = "insert into recordinfo11(starttime,endtime,size,pieceinfo) values(";
strSql = strSql + "'" + recordFileBlockt.fileStartTime + "'" + ",";
strSql = strSql + "'" + recordFileBlockt.fileEndTime + "'" + ",";
strSql = strSql + "'" + "6666" + "'" + ",";
strSql = strSql + "'" + InterfaceSerial.XMLSerialize(recordFileBlockt) + "'" + ")";
dBMysql.SqlExe(strSql);
string strMaxId = "select max(id) as id from recordinfo11";
DataSet dataSet = new DataSet();
dBMysql.SqlExe(strMaxId, ref dataSet);
Console.WriteLine(dataSet.Tables[0].Rows[0]["id"]);
输出截图: