Insert comma separated values in single column of mysql table using c# -


i have many fields has comma separated values in it. have insert them in mysql table

hometoschool[0] = "name"; hometoschool[1] = "mumbai, 400080, india"; hometoschool[2] = "malad, mg";  var cmdtext ="insert schoolschedule(name, from, to) values (@name, @from, @to)"; cmd.parameters.addwithvalue("@name", hometoschool[0]); cmd.parameters.addwithvalue("@from", hometoschool[1]); cmd.parameters.addwithvalue("@to", hometoschool[2]); connection.open(); cmd.executenonquery(); 

i getting error due comma separated values.

i bet error message this:

"you have error in sql syntax; check manual corresponds mysql server version right syntax use near 'from, to) values.."

actually problem not value. it's on column name used , didn't escape causing syntax error.

from , to reserved keywords. can still used provided wrapp them backticks.

insert schoolschedule(name, `from`, `to`) values (@name, @from, @to) 

if have chance alter table, change column name not reserved keyword. avoid getting problems in future.


Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -