Please i want my application to display the autogenerated ID in a messagebox after an insert has taken place and this autogenertaed id is a GUID form.

Please help, i have tried @@identity and select_identity() but it wont display any value.

Heres how my code is from d insert section

   command.CommandText = "INSERT INTO dbo.Clients (FirstName, LastName, Organisation, Address, Purpose, PhoneNo, Time ) VALUES (@fnames, @lnames, @organisatn, @addres, @purposes, @phone, @tim );"+"SELECT @@IDENTITY";

    command.Parameters.Add("@fnames", SqlDbType.VarChar).Value = Fname.Text;
    command.Parameters.Add("@lnames", SqlDbType.VarChar).Value = Lname.Text;
    command.Parameters.Add("@organisatn", SqlDbType.VarChar).Value = org.Text;
    command.Parameters.Add("@addres", SqlDbType.VarChar).Value = addy.Text;
    command.Parameters.Add("@purposes", SqlDbType.VarChar).Value = purpos.Text;
    command.Parameters.Add("@phone", SqlDbType.Int).Value = fone.Text;
    command.Parameters.Add("@tim", SqlDbType.DateTime).Value = tims.Value;

  object oo = command.ExecuteScalar();
  MessageBox.Show(string.Format("Your Reference code is "+oo), "PIN", MessageBoxButtons.OK, MessageBoxIcon.Information);
6 Years
Discussion Span
Last Post by Momerath

Assuming you are using uniqueidentifier as the type for the ID, you should read this page, noting in particulare (bolded part added)

Columns created with the uniqueidentifier data type store specially formatted 16-byte binary values. Unlike with identity columns, the Database Engine does not automatically generate values for columns with the uniqueidentifier data type. During an insert operation, variables with a data type of uniqueidentifier and string constants in the form xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx (36 characters including hyphens, where x is a hexadecimal digit in the range 0-9 or a-f) can be used for uniqueidentifier columns. For example, 6F9619FF-8B86-D011-B42D-00C04FC964FF is a valid value for a uniqueidentifier variable or column. Use the NEWID() function to obtain a globally unique ID (GUID).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.