这是生成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没有存到数据库里呢...数据库里的那个字段是空的什么也没有,请帮忙
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没有存到数据库里呢...数据库里的那个字段是空的什么也没有,请帮忙
解决方案 »
- vs2005 js遍历treeview 时TreeView1.getChildren(); 对象不支持此属性或方法
- 请教大家,如何跨框架取值?
- cookie问题
- 做ASP网站初期,遇到数据库方面的问题请高手赐教
- 怎样让asp.net支持中文?
- 请问webform中如何调用系统自带的计算器程序?
- vb中给数据库插入5个表关联的数据 每次到执行的时候就报错 但是检查不出错误 在插入的过程中与sql语句的复杂程度有关系吗?
- 需要一份能发在线消息的源代码
- ContextUtil
- 在ASPNET中实现打印的问题。来者有分!
- 在VS2003下正常,2005下提示:未将对象引用设置到对象的实例
- 怎样给web.config文件添加节点?
不就可以产生一个guid吗......char 36当然没有关系,你只要赋一个字符串类型就可以了.我的看法是最后将这一列设置唯一约束.