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. how to create an autoincrement id [modified]

how to create an autoincrement id [modified]

Scheduled Pinned Locked Moved C#
databasehelptutorialquestion
1 Posts 1 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.
  • B Offline
    B Offline
    balanjingot
    wrote on last edited by
    #1

    hi, how to create an autoincrement id to be displayed on a textbox? the id will then be stored in the database table... i have already created my code for that problem but it behaves differently.it behaves like this...if the current value of my pur_requestid in the table is null, then there would be no value displayed in the textbox. but if i inserted a value like 1 then when i execute my program the textbox receives 2. i want my textbox to automatically display 1 eventhough i will NOT insert a value on my table. my code that behaves differently...supposed to be the event being fired is when the user clicks the button NEW a purchase request id will be generated.. private void button7_Click(object sender, EventArgs e) { MySqlDataReader reader = null; try { String query = "Select last_insert_id(pur_requestid) as lastinsertedid from purchaserequest where lpur_requestid = null order by pur_requestid desc limit 1"; MySqlCommand command = new MySqlCommand(query, connection); reader = command.ExecuteReader(); if (reader.Read()) { currentId = reader.GetInt64("lastinsertedid"); currentId = currentId + 1; textBox1.Text = currentId.ToString(); } } catch (MySqlException mse) { MessageBox.Show(mse.Message); } finally { if (reader != null) { reader.Close(); } } thanks, hoping for your reply... regards:) -- modified at 22:59 Tuesday 8th May, 2007

    jing

    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