sql - C# MySQL claims a field is too long -
here's sql:
create table patients ( patient_id int auto_increment not null, last_name varchar(64) not null, first_name varchar(64), sex char(1), birth date, death date, primary key (patient_id) ) engine=innodb;
and here's c#:
mysqlcommand insertcom = new mysqlcommand("insert patients(" + "last_name, first_name, sex, birth) values" + "('@lastname', '@firstname', '@sex', '@birthdate')", connection); /* ... */ insertcom.parameters.add("@lastname", mysqldbtype.varchar, 64); insertcom.parameters.add("@firstname", mysqldbtype.varchar, 64); insertcom.parameters.add("@sex", mysqldbtype.char, 1); insertcom.parameters.add("@birthdate", mysqldbtype.date); insertcom.parameters["@lastname"].value = lastnamebox.text; insertcom.parameters["@firstname"].value = firstnamebox.text; insertcom.parameters["@sex"].value = (sexbox.text == "male" ? 'm' : 'f'); insertcom.parameters["@birthdate"].value = birthdatepicker.text;
this how enter data directly in sql:
insert patients(last_name, first_name, sex, birth, death) values ('delarge', 'alexandra', 'f', '1975-12-02', null)
the above works , wrote c# code based on that. c# code produces this: mysql.data.mysqlclient.mysqlexception: data long column 'sex' @ row 1
. gives?
you should not have single quotes around parameter names. try instead:
mysqlcommand insertcom = new mysqlcommand("insert patients(" + "last_name, first_name, sex, birth) values" + "(@lastname, @firstname, @sex, @birthdate)", connection);
Comments
Post a Comment