public bool Add(KingToon.Model.Users model)
{
StringBuilder strSql=new StringBuilder();
strSql.Append("insert into Users(");
strSql.Append("id,num,name,passw,class_id,profession,remark,authority_id)");
strSql.Append(" values (");
strSql.Append("@id,@num,@name,@passw,@class_id,@profession,@remark,@authority_id)");
SQLiteParameter[] parameters = {
new SQLiteParameter("@id", DbType.Guid,16),
new SQLiteParameter("@num", DbType.String,512),
new SQLiteParameter("@name", DbType.String,512),
new SQLiteParameter("@passw", DbType.String,512),
new SQLiteParameter("@class_id", DbType.Guid,16),
new SQLiteParameter("@profession", DbType.String,512),
new SQLiteParameter("@remark", DbType.String,1024),
new SQLiteParameter("@authority_id", DbType.Guid,16)};
parameters[0].Value = Guid.NewGuid();
parameters[1].Value = model.num;
parameters[2].Value = model.name;
parameters[3].Value = model.passw;
parameters[4].Value = model.class_id;
parameters[5].Value = model.profession;
parameters[6].Value = model.remark;
parameters[7].Value = model.authority_id;
int rows=DbHelperSQLite.ExecuteSql(strSql.ToString(),parameters);
if (rows > 0)
{
return true;
}
else
{
return false;
}
}
須要注意的是:這裏必定要使用ToByteArray()方法,而後再轉換成16進制字符串,緣由是GUID的文本表示和二進制的存儲順序並非徹底同樣,若是要知道具體的順序,debug一下ToByteArray返回的結果就知道了。