How to add data into mysql using c# (edit table column on combo box selection ) -


i want add item in table in database in mysql based upon user has selected in items combobox.

eg: if person chooses tea (this event should populate tea column in table) , fills quantity 2 want add 2 under column name tea in mysql table . i'm trying use update statement, gives error syntax not correct.the column filled in table changes if user chooses tea or coffee that's why have used "+this.items.text+"

"update employee.transaction    set   department = ' " + this.department.text + " ',   ' " + this.items.text + " ' =  ' " + this.quantity.text + " ' ,   billno = ' " + this.bill_no_txt.text + "'    billno = ' " + this.bill_no_txt.text + " ' ;";

i might see several points in query cause problems. lets go through it:

set   department = ' " + this.department.text + " ', 

please make sure enter right data database. in sql queries need make sure have no spaces if enter text text or varchar field. enter above " text " , not "text" (mind spaces). following enter text without space @ beginning , end:

set   department = '" + this.department.text + "', 

what's causing error is:

billno = ' " + this.bill_no_txt.text + "' 

i assume billno column defined int (which correct). have make sure insert such. using ' (single brakets) trying enter text int field, cause error. can not sure since can't see table definitions of table want update data in.

what else cause problem column name wrong here:

 ' " + this.items.text + " ' =  ' " + this.quantity.text + " ' ,   ' " + this.items.text + " '  

will basickly enter "' columnname '" wrong (with "'" , spaces). probabely should "columnname". try without spaces , without singlebackets:

 " + this.items.text + " =  '" + this.quantity.text + "' , 

but despite of think have architectural problem in database... if have 30 different beverages need have 30 columns can done n n relationship between 3 column table , 2 column table. suggest bit first.

heres corrected query make sure understand changes:

update employee.transaction set  department = '" + this.department.text + "'," + this.items.text +" =  '" + this.quantity.text + "' , billno = " + this.bill_no_txt.text + " billno = " + this.bill_no_txt.text + "; 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

javascript - Chrome Extension: Interacting with iframe embedded within popup -