Ceriwis  

Go Back   Ceriwis > HOBI > Komputer & Teknologi > Programming

Programming Share, tanya jawab, saling bantu antar programmer dengan berbagai macam bahasa pemrograman.

Reply
 
Thread Tools
  #1  
Old 20th November 2011
Linuxmania Linuxmania is offline
Ceriwiser
 
Join Date: Nov 2011
Posts: 392
Rep Power: 14
Linuxmania mempunyai hidup yang Normal
Default [ASK] cara generate last code from table /data grid view

gan.. ane need help nh..

mw insert data tapi kn mesti generate new code misalnya

row sebelumnya id nya F001

nah pas klik insert dy auto generate jadi F002..

gmn caranya ya??

ane dah dpt codign tp eror gini gk as di klik insert

ane pake bahasa C#..





//generate new ID

String newcode = "";

string lastid = TabelBuku.Rows[TabelBuku.Rows.Count - 1].Cells[0].Value.ToString();

string newid = "KP";

int id = int.Parse(lastid.Substring(1, 3));

id++;



if (id < 9)

{

newid += "00" + id.ToString();

}

else if (id < 99)

{

newid += "0" + id.ToString();

}

else

{

newid += id.ToString();

}



///////////////////////////////////

newcode = newid;

KodeBuku.Text = newcode;





yg tulisan tabel karyawan ntu maksudnya data grid view yg ane rename gan..

o iy yg ini >> int id = int.Parse(lastid.Substring(1, 3));

Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off


 


All times are GMT +7. The time now is 02:28 AM.


no new posts