c# - Calling (ID_number) primary key to textbox using Combobox(Category Description) -
dealing foreign key using ms access in c#.
each time select category description(catdesc) using combobox category table, wanted get/call automatically category id(catid) in textbox1.
my code doesn't worked, , no errors given.
this sample_code:
private void cmdcategoryy_textchanged(object sender, eventargs e) { categorydesc(); } void categorydesc() { oledbconnection mycon = new oledbconnection(@"provider = microsoft.ace.oledb.12.0; data source = c:\users\blabla\desktop\docsmonitorg\try 081517\windowsformsapp6\windowsformsapp6\database.accdb"); string con; try { con = "select catid, catdesc category catdesc = '" + cmdcategoryy.text + "' "; mycon.open(); oledbcommand cm = new oledbcommand(); oledbdataadapter da = new oledbdataadapter(); datatable mydata1 = new datatable(); cm.commandtext = con; cm.connection = mycon; int i; da.selectcommand = cm; da.fill(mydata1); (i = 0; <= mydata1.rows.count - 1;) textbox1.text = (mydata1.rows[i]["catid"].tostring()); } catch (exception ex) { messagebox.show(ex.message, "message", messageboxbuttons.ok, messageboxicon.error); } { mycon.close(); mycon.dispose(); } }
this database sample:
category description has graphic desginer, autocat, ax staff category id 1,2,3
i hide textbox1. , godbless!.
wiki
Comments
Post a Comment