Guid handling

Discussion in 'ASP .Net' started by Igor, Jun 14, 2008.

  1. Igor

    Igor Guest

    Hi

    I have a drop down list on my page that lists some items returned from a
    database. Each item has its GUID (or uniqueidentifier). I have to (in code
    behind of the page) read this GUID, to hand it over to a query (stored
    procedure) that takes the GUID and looks for some data in a specific table.
    I don't know have to hand it to the query as GUID.

    SqlCommand myCommand = new SqlCommand();
    myCommand.Connection = myConnection;

    myCommand.CommandText = "dbo.tbh_GetBoundIdentifier";
    myCommand.CommandType = CommandType.StoredProcedure;

    string BoundID =
    DropDownList4.SelectedItem.Value.ToString();

    SqlParameter myParameter1 = new SqlParameter();
    myParameter1.ParameterName = "@BoundID";
    myParameter1.SqlDbType = SqlDbType.UniqueIdentifier;
    myParameter1.Value = BoundID;

    SqlParameter myParameter2 = new SqlParameter();
    myParameter2.ParameterName = "@BoundIdentifier";
    myParameter2.SqlDbType = SqlDbType.Char;
    myParameter2.Direction = ParameterDirection.Output;

    myCommand.Parameters.Add(myParameter1);
    myCommand.Parameters.Add(myParameter2);

    myConnection.Open();

    SqlDataReader myReader = myCommand.ExecuteReader();
    WIth the code above I get the following error: "Failed to convert parameter
    value from a String to a Guid" when trying to execute the command
    myCommand.ExecuteReader();. How can I handle (or convert) the GUID so it is
    handed as GUID and not as a string?
     
    Igor, Jun 14, 2008
    #1
    1. Advertising

  2. Igor

    Igor Guest

    Found solution myself:

    Guid BoundID = new Guid(DropDownList4.SelectedItem.Value.ToString());


    Regards
    "Igor" <> wrote in message
    news:...
    > Hi
    >
    > I have a drop down list on my page that lists some items returned from a
    > database. Each item has its GUID (or uniqueidentifier). I have to (in code
    > behind of the page) read this GUID, to hand it over to a query (stored
    > procedure) that takes the GUID and looks for some data in a specific
    > table. I don't know have to hand it to the query as GUID.
    >
    > SqlCommand myCommand = new SqlCommand();
    > myCommand.Connection = myConnection;
    >
    > myCommand.CommandText = "dbo.tbh_GetBoundIdentifier";
    > myCommand.CommandType = CommandType.StoredProcedure;
    >
    > string BoundID =
    > DropDownList4.SelectedItem.Value.ToString();
    >
    > SqlParameter myParameter1 = new SqlParameter();
    > myParameter1.ParameterName = "@BoundID";
    > myParameter1.SqlDbType = SqlDbType.UniqueIdentifier;
    > myParameter1.Value = BoundID;
    >
    > SqlParameter myParameter2 = new SqlParameter();
    > myParameter2.ParameterName = "@BoundIdentifier";
    > myParameter2.SqlDbType = SqlDbType.Char;
    > myParameter2.Direction = ParameterDirection.Output;
    >
    > myCommand.Parameters.Add(myParameter1);
    > myCommand.Parameters.Add(myParameter2);
    >
    > myConnection.Open();
    >
    > SqlDataReader myReader = myCommand.ExecuteReader();
    > WIth the code above I get the following error: "Failed to convert
    > parameter value from a String to a Guid" when trying to execute the
    > command myCommand.ExecuteReader();. How can I handle (or convert) the GUID
    > so it is handed as GUID and not as a string?
    >
    >
     
    Igor, Jun 14, 2008
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. LL

    GUID?

    LL, Nov 3, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    758
    Atila B.
    Nov 4, 2003
  2. Sky
    Replies:
    2
    Views:
    462
  3. Grey

    Create GUID

    Grey, May 6, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,917
    =?Utf-8?B?UmF2aWthbnRoW01WUF0=?=
    May 6, 2004
  4. Grey

    Using GUID as primary key in DB

    Grey, May 7, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    1,922
    Steve C. Orr [MVP, MCSD]
    May 7, 2004
  5. Gopal Krish
    Replies:
    3
    Views:
    5,675
    Gopal Krish
    Oct 27, 2004
Loading...

Share This Page