title: Arithmetic overflow error converting expression to data type nvarchar
body: <p>I am creating a helpdesk system but seem to of run into a slight problem, when the user clicks a button to "pre register" the helpdesk ticket number, my script fires off to the SQL Express server, creating a new row -> gets the row ID -> Uses the row ID to create the final ticket ref (in the format of RAD000001 for example for row 1) this process seems to work for me fine, until i get to number 9... when the user clicks the "create new Ticket ref" button(Generating ticket number 10) i get the following error:</p>
  
  <pre><code>Arithmetic overflow error converting expression to data type nvarchar.
  </code></pre>
  
  <p>It creates the row, but seems to fail on the update(the row is created, the ID returned and then the ref created from the ID)</p>
  
  <p>My SQL table is looks like this:</p>
  
  <pre><code>CREATE TABLE [dbo].[tickets](
      [id] [int] IDENTITY(1,1) NOT NULL,
      [ticket_ref] [varchar](15) NULL,
      [details_id] [int] NULL,
      [state] [int] NULL,
      [create_date_Time] [datetime] NOT NULL,
      [details_subject] [varchar](255) NULL,
      [details_main_body] [text] NULL
  ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
  </code></pre>
  
  <p>and this is the c# code behind:</p>
  
  <pre><code>private string Reform_TicketId(string original_ticket_id)
  {
      switch (original_ticket_id.Length)
      {
          case 1:
              return "RAD00000" + original_ticket_id.ToString();
          case 2:
              return "RAD0000" + original_ticket_id.ToString();
          case 3:
              return "RAD000" + original_ticket_id.ToString();
          case 4:
              return "RAD00" + original_ticket_id.ToString();
          case 5:
              return "RAD0" + original_ticket_id.ToString();
          case 6:
              return "RAD" + original_ticket_id.ToString();
          default:
              return "ERROR!";
      }
  }
  
  protected void DsCreateTicketEntry_Inserted(object sender, SqlDataSourceStatusEventArgs e)
  {
      string original_id = e.Command.Parameters["@ticket_id"].Value.ToString();
      string reformed_id = Reform_TicketId(original_id.ToString()).ToString();
  
      if (original_id != "0")
      {
          //It has returned a value that is a DB ID field and seems correct! lets proceed!
          DsCreateTicketEntry.UpdateParameters["ticket_db_id"].DefaultValue = original_id;
          //DsCreateTicketEntry.UpdateParameters["new_ticket_id"].DefaultValue = reformed_id;
          DsCreateTicketEntry.UpdateParameters["new_ticket_id"].DefaultValue = "RAD000002";
          DsCreateTicketEntry.Update();
          LblTicketOutput.Text = reformed_id;
      }
      else
      {
          //@TODO: Write to the label stating we had problems generating a Ticket ID!
      }
  }
  
  protected void btnCreateTicket_Click(object sender, EventArgs e)
  {
      DsCreateTicketEntry.Insert();
      btnCreateTicket.Enabled = false;
  }
  </code></pre>
  
  <p>with the following queries in my SQLDataSource:</p>
  
  <pre><code>InsertCommand="INSERT INTO tickets(state, create_date_Time) VALUES (1,GETDATE()) SET @ticket_id=SCOPE_IDENTITY();"    
  UpdateCommand="UPDATE tickets SET ticket_ref = @new_ticket_id WHERE (id = @ticket_db_id)"
  </code></pre>
  
  <p>Hopfully someone is able to cast some light on where i am going wrong!? I have been looking at this code all day, and its fallen slightly outside my league of learning...</p>