Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Uniqueidentifier

Uniqueidentifier

Scheduled Pinned Locked Moved C#
helpquestioncsharpdatabasevisual-studio
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • P Offline
    P Offline
    pat270881
    wrote on last edited by
    #1

    Hello, I want to save the name of the company in the textBox2. The problem which occur is with the JobId. I will get the JobId number from a previous page as a string. Here I have quoted an example JobId. (the JobIds are saved in the database as uniqueidentifier). The Problem occurs in the ExecuteReader. I think it concerns that the parameter @JobId is of type uniqueidentifier and the the quoted jobId here is from type string. So it occurs a Data conversion failed. error. jobId = "D4DF269F-F9FB-4C88-A005-11C98B38818A"; this.dataSource = "\\Program Files\\MobileHelpDesk.sdf"; this.strConn = "Data Source = " + dataSource; this.connection = new SqlCeConnection("Data Source = " + dataSource); SqlCeCommand command = new SqlCeCommand(); command.Connection = connection; command = connection.CreateCommand(); command.CommandText = "SELECT c.CompanyName, c.ContactLName FROM Client c INNER JOIN JobDescription p ON p.EmailClient = c.Email WHERE p.JobId = ?"; command.Parameters.Add( "@JobId", jobId); connection.Open(); drdrDB = command.ExecuteReader(); while (drdrDB.Read()) { textBox2.Text = drdrDB["JobId"].ToString(); } drdrDB.Close(); connection.Close(); Does anybody know how can I solve this problem or parse the jobId string in the corresponding type?? or is there another error? But the Select String is correct, I tried it in VS.NET. thx patrick

    C 1 Reply Last reply
    0
    • P pat270881

      Hello, I want to save the name of the company in the textBox2. The problem which occur is with the JobId. I will get the JobId number from a previous page as a string. Here I have quoted an example JobId. (the JobIds are saved in the database as uniqueidentifier). The Problem occurs in the ExecuteReader. I think it concerns that the parameter @JobId is of type uniqueidentifier and the the quoted jobId here is from type string. So it occurs a Data conversion failed. error. jobId = "D4DF269F-F9FB-4C88-A005-11C98B38818A"; this.dataSource = "\\Program Files\\MobileHelpDesk.sdf"; this.strConn = "Data Source = " + dataSource; this.connection = new SqlCeConnection("Data Source = " + dataSource); SqlCeCommand command = new SqlCeCommand(); command.Connection = connection; command = connection.CreateCommand(); command.CommandText = "SELECT c.CompanyName, c.ContactLName FROM Client c INNER JOIN JobDescription p ON p.EmailClient = c.Email WHERE p.JobId = ?"; command.Parameters.Add( "@JobId", jobId); connection.Open(); drdrDB = command.ExecuteReader(); while (drdrDB.Read()) { textBox2.Text = drdrDB["JobId"].ToString(); } drdrDB.Close(); connection.Close(); Does anybody know how can I solve this problem or parse the jobId string in the corresponding type?? or is there another error? But the Select String is correct, I tried it in VS.NET. thx patrick

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      The parameter value needs to be a System.Guid[^] if the SQL Server type is a uniqueidentifier. For example:

      Guid jobGuid = new Guid(jobId);
      command.Parameters.Add("@JobId", jobGuid);


      Do you want to know more?


      Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.

      P 1 Reply Last reply
      0
      • C Colin Angus Mackay

        The parameter value needs to be a System.Guid[^] if the SQL Server type is a uniqueidentifier. For example:

        Guid jobGuid = new Guid(jobId);
        command.Parameters.Add("@JobId", jobGuid);


        Do you want to know more?


        Vogon Building and Loan advise that your planet is at risk if you do not keep up repayments on any mortgage secured upon it. Please remember that the force of gravity can go up as well as down.

        P Offline
        P Offline
        pat270881
        wrote on last edited by
        #3

        Thank you very much, now it works! patrick

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups