0

C# code: //Here i trying to insert values in my table.

 case true:
     Connection.Connect();
     int fk_pic = IdPic();
     string insertWork = "INSERT INTO work (fk_id_pic, fk_login, university, lesson, name, info, date_work, price) VALUES (@fk_pic, @fk_login, @university, @lesson, @name, @info, @date_work, @price); Allow User Variables = true;";
     MySqlCommand work = new MySqlCommand(insertWork, Connection.Connect());
     work.Parameters.AddWithValue("@fk_pic", fk_pic);
     work.Parameters.AddWithValue("@fk_login", Program.form1.login);
     work.Parameters.AddWithValue("@university", textBox1.Text);
     work.Parameters.AddWithValue("@lesson", textBox2.Text);
     work.Parameters.AddWithValue("@name", textBox3.Text);
     work.Parameters.AddWithValue("@info", richTextBox1.Text);
     work.Parameters.AddWithValue("@date_work", DateTime.Now);
     work.Parameters.AddWithValue("@ price", textBox4.Text);
     work.ExecuteNonQuery();
     Connection.Disconnect();
     break;

SQL Query:

CREATE TABLE pic 
( 
  id_pic INTEGER UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'id of image', 
  caption CHAR(45) NOT NULL COMMENT 'the name of image',
  who_add CHAR(30) NOT NULL COMMENT 'who add this image',
  img LONGBLOB NOT NULL, 
  CONSTRAINT pkId_pic PRIMARY KEY(id_pic) 
) 
COMMENT 'Table for hosting images';

Don't know what to do. Waiting for response)

svick
  • 236,525
  • 50
  • 385
  • 514
IanGraham
  • 45
  • 1
  • 1
  • 3

2 Answers2

0

Change the name of the column or variable called "name".

name/Name is usually a reserved word.

that might be the problem.

Etnozam
  • 26
  • 2
-1

Remember that the parameter identifier in mysql .net connector is ? and not @

Random comment

Looking at the SQL code i noticed that you use char for fields that sounds more like varchar fields. When you define a column as char it will reserve the defined amount of space for all entries you put into the table.

Example:

create table test (
    myvalue char(255)
)

no matter if you only wite "a" or "hello world" into the myvalue column it will reserve the space of a string with 255 characters on the disk. Just have it in mind.

aweis
  • 5,350
  • 4
  • 30
  • 46