如何将Guid读入sqlserver的uniqueidentifier字段里去

来源:互联网 发布:java double 误差 编辑:程序博客网 时间:2024/05/04 11:34
在SQL   server   northwind建立表Test  
  cola   varchar   50  
  colb   uniqueidentifier   16  
   
   
  页面文件中:  
   
  string   str;  
  str   =   @"server=localhost;uid=sa;pwd=sa;database=northwind";  
  SqlConnection   cn   =   new   SqlConnection(str);  
  str   =   "INSERT   INTO   Test(cola,   colb)   Values   (@a,   @b)";  
  SqlCommand   cmd   =   new   SqlCommand(str,   cn);  
  cmd.Parameters.Add("@a",SqlDbType.VarChar).Value   =   "aa";  
  cmd.Parameters.Add("@b",SqlDbType.UniqueIdentifier).Value   =   new   Guid(System.Guid.NewGuid().ToString());  
   
  cn.Open();  
  int   i   =   cmd.ExecuteNonQuery();  
   
  if   (i   !=   0)  
  Response.Write   ("操作查询已执行");  
  cn.Close();   
 
原创粉丝点击