C# guid and SQL uniqueidentifier

前端 未结 5 1767
你的背包
你的背包 2020-11-27 15:37

I want to create a GUID and store it in the DB.

In C# a guid can be created using Guid.NewGuid(). This creates a 128 bit integer. SQL Server has a uniqueidentifier

5条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-11-27 16:23

    // Create Instance of Connection and Command Object
    SqlConnection myConnection = new SqlConnection(GentEFONRFFConnection);
    myConnection.Open();
    SqlCommand myCommand = new SqlCommand("your Procedure Name", myConnection);
    myCommand.CommandType = CommandType.StoredProcedure;
    myCommand.Parameters.Add("@orgid", SqlDbType.UniqueIdentifier).Value = orgid;
    myCommand.Parameters.Add("@statid", SqlDbType.UniqueIdentifier).Value = statid;
    myCommand.Parameters.Add("@read", SqlDbType.Bit).Value = read;
    myCommand.Parameters.Add("@write", SqlDbType.Bit).Value = write;
    // Mark the Command as a SPROC
    
    myCommand.ExecuteNonQuery();
    
    myCommand.Dispose();
    myConnection.Close();
    

提交回复
热议问题