这是生成GUID的代码.我测试了是正确的可以生成..
private static string shoppingCartId
{
get
{
HttpContext current = HttpContext.Current;
string str = "";
object obj2 = current.Session["bookShop_CartID"];
if (obj2 != null)
{
str = obj2.ToString();
}
if (str != null)
{
return str;
}
if (current.Request.Cookies["bookShop_CartID"] != null)
{
str = current.Request.Cookies["bookShop_CartID"].Value;
current.Session["bookShop_CartID"] = str;
return str;
}
else
{
str = Guid.NewGuid().ToString();
HttpCookie cookie = new HttpCookie("bookShop_CartID", str.ToString());
int cartPersistDays = configuration.CartPersistDays;
DateTime now = DateTime.Now;
TimeSpan span = new TimeSpan(cartPersistDays, 0, 0, 0);
DateTime time2 = now.Add(span);
cookie.Expires = time2;
current.Response.Cookies.Add(cookie);
current.Session["bookShop_CartID"] = str;
return str.ToString();
}
}
}
我是这样调用的
SqlCommand command = DataAccess.CreateCommand();
command.CommandText = "ShoppingCartAddItem";
SqlParameter parameter = command.CreateParameter();
parameter.ParameterName = "@cartID";
parameter.Value = shoppingCartId;
parameter.SqlDbType = SqlDbType.Char;
parameter.Size = 0x24;
command.Parameters.Add(parameter);
parameter = command.CreateParameter();
parameter.ParameterName = "@bookID";
parameter.Value = bookID;
parameter.SqlDbType = SqlDbType.Int;
command.Parameters.Add(parameter);
为什么GUID没有存到数据库里呢...数据库里的那个字段是空的什么也没有,请帮忙
------解决方案--------------------------------------------------------
parameter.SqlDbType = SqlDbType.UniqueIdentifier;
------解决方案--------------------------------------------------------