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