Convert int datatype to string datatype c# access database


hi guys, created windows application form project , there problem facing right now. had array of textboxes, , wanted connect database textboxes, however, cannot data because data want connect int datatype.

there 2 form has been created, 1 login form, login form, database string, autocomplete working. second 1 second form, second form, database int, autocomplete not working.

please help.

here code second form:

string connectionstring = (@"provider=microsoft.ace.oledb.12.0;data source=\archives\projects\program\sell system\sell system\app_data\db1.accdb;persist security info=false;");      private list<list<textbox>> textboxcodecontainer = new list<list<textbox>>();      oledbdatareader dreader;     oledbconnection conn = new oledbconnection(connectionstring);     conn.open();     oledbcommand cmd = new oledbcommand("select distinct [code] [data] order [code] asc", conn);     dreader = cmd.executereader();     autocompletestringcollection codescollection = new autocompletestringcollection();      while (dreader.read())     {     codescollection.add(convert.tostring(dreader.getint32(dreader.getordinal("code")))); // line not working     }  //****textbox code****             (int y = 0; y <= 16; y++)             {                 textboxcodecontainer.add(new list<textbox>());                 textboxcodecontainer[0].add(new textbox());                 textboxcodecontainer[0][y].size = new size(100, 50);                 textboxcodecontainer[0][y].location = new point(25, 150 + (y * 25));                  textboxcodecontainer[0][y].autocompletemode = autocompletemode.suggest;                 textboxcodecontainer[0][y].autocompletesource = autocompletesource.customsource;                 textboxcodecontainer[0][y].autocompletecustomsource = codescollection;                  dreader.close();                 conn.close();                  controls.add(textboxcodecontainer[0][y]);             }

edit: data type code number, field size long integer , format 0000.. 0 behind replaced number "1", "2" , on.

edit: ****complete code****

using system; using system.collections.generic; using system.componentmodel; using system.data; using system.drawing; using system.linq; using system.text; using system.windows.forms; using system.security.principal; using system.data.oledb;  namespace sell_system {     public partial class form2 : form     {         string connectionstring = (@"provider=microsoft.ace.oledb.12.0;data source=\archives\projects\program\sell system\sell system\app_data\db1.accdb;persist security info=false;");         private form1 firstform;         private list<list<textbox>> textboxcodecontainer = new list<list<textbox>>();         private list<list<textbox>> textboxquantitycontainer = new list<list<textbox>>();         private list<list<textbox>> textboxdesccontainer = new list<list<textbox>>();         private list<list<textbox>> textboxsubtotalcontainer = new list<list<textbox>>();         private list<list<textbox>> textboxtotalcontainer = new list<list<textbox>>();          public form2()         {             initializecomponent();         }          public form2(form1 firstform)             : this()         {             this.firstform = firstform;         }          private void form2_load(object sender, eventargs e)         {             //var int num = 10;              oledbdatareader dreader;             oledbconnection conn = new oledbconnection(connectionstring);             conn.open();             oledbcommand cmd = new oledbcommand("select distinct [code] [data] order [code] asc", conn);             dreader = cmd.executereader();             autocompletestringcollection codescollection = new autocompletestringcollection();              while (dreader.read())             {                 codescollection.add(convert.tostring(dreader.getint32(dreader.getordinal("code"))));                 //codescollection.add(convert.tostring(num);             }              if (firstform.combobox1.selectedindex == 0)             {                 label1.text = "code:";                 label1.location = new point(60, 125);                 label2.text = "welcome selling system.";                 label2.location = new point(600, 0);                 label3.text = "quantity:";                 label3.location = new point(155, 125);                 label4.text = "description:";                 label4.location = new point(580, 125);                 label5.text = "sub total on rp:";                 label5.location = new point(1020, 125);                 label6.text = "total on rp:";                 label6.location = new point(1210, 125);                 label7.text = "total on rp:";                 label7.location = new point(1080, 580);             }              else if (firstform.combobox1.selectedindex == 1)             {                 label1.text = "kode:";                 label1.location = new point(60, 125);                 label2.text = "selamat datang di selling system.";                 label2.location = new point(600, 0);                 label3.text = "banyaknya:";                 label3.location = new point(145, 125);                 label4.text = "keterangan:";                 label4.location = new point(580, 125);                 label5.text = "sub total di rp:";                 label5.location = new point(1020, 125);                 label6.text = "total di rp:";                 label6.location = new point(1210, 125);                 label7.text = "total di rp:";                 label7.location = new point(1080, 580);             }              //****textbox code****             (int y = 0; y <= 16; y++)             {                 textboxcodecontainer.add(new list<textbox>());                 textboxcodecontainer[0].add(new textbox());                 textboxcodecontainer[0][y].size = new size(100, 50);                 textboxcodecontainer[0][y].location = new point(25, 150 + (y * 25));                  textboxcodecontainer[0][y].autocompletemode = autocompletemode.suggest;                 textboxcodecontainer[0][y].autocompletesource = autocompletesource.customsource;                 textboxcodecontainer[0][y].autocompletecustomsource = codescollection;                  dreader.close();                 conn.close();                  controls.add(textboxcodecontainer[0][y]);             }              //****textbox quantity****             (int y = 0; y <= 16; y++)             {                 textboxquantitycontainer.add(new list<textbox>());                 textboxquantitycontainer[0].add(new textbox());                 textboxquantitycontainer[0][y].size = new size(100, 50);                 textboxquantitycontainer[0][y].location = new point(125, 150 + (y * 25));                  controls.add(textboxquantitycontainer[0][y]);             }              //****textbox description****             (int y = 0; y <= 16; y++)             {                 textboxdesccontainer.add(new list<textbox>());                 textboxdesccontainer[0].add(new textbox());                 textboxdesccontainer[0][y].size = new size(750, 50);                 textboxdesccontainer[0][y].location = new point(225, 150 + (y * 25));                  controls.add(textboxdesccontainer[0][y]);             }              //****textbox sub total****             (int y = 0; y <= 16; y++)             {                 textboxsubtotalcontainer.add(new list<textbox>());                 textboxsubtotalcontainer[0].add(new textbox());                 textboxsubtotalcontainer[0][y].size = new size(175, 50);                 textboxsubtotalcontainer[0][y].location = new point(975, 150 + (y * 25));                  controls.add(textboxsubtotalcontainer[0][y]);             }              //****textbox total****             (int y = 0; y <= 16; y++)             {                 textboxtotalcontainer.add(new list<textbox>());                 textboxtotalcontainer[0].add(new textbox());                 textboxtotalcontainer[0][y].size = new size(175, 50);                 textboxtotalcontainer[0][y].location = new point(1150, 150 + (y * 25));                  controls.add(textboxtotalcontainer[0][y]);             }              //****textbox total all****             textbox textboxalltotal = new textbox();             textboxalltotal.size = new size(175, 50);             textboxalltotal.location = new point(1150, 575);              controls.add(textboxalltotal);         }     } }

it working sir bonnieb, , also, solved myself:

here code:

while (dreader.read())             {                 string numstring = dreader[0].tostring().padleft(4, '0'); // data "code" integer , convert string                 codescollection.add(numstring); // display string in autocompletestringcollection             }

thank guys. appreciate of helps

sincerely,

fuhans




Visual Studio Languages  ,  .NET Framework  >  Visual C#



Comments

Popular posts from this blog

Azure DocumentDB Owner resource does not exist

BizTalk Server 2013 Azure VM Log Shipping and HA for hosts

How to Share webservice object to all user