0

C# 代码: //在这里我试图在我的表中插入值。

 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查询:

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';

不知道该怎么办。等待答复)

4

2 回答 2

0

更改名为“name”的列或变量的名称。

name/Name 通常是保留字。

这可能是问题所在。

于 2013-02-03T15:26:50.620 回答
-1

请记住,mysql .net 连接器中的参数标识符是?而不是@

随机评论

查看 SQL 代码,我注意到您使用char的字段听起来更像varchar字段。当您将列定义为 char 时,它将为您放入表中的所有条目保留定义的空间量。

例子:

create table test (
    myvalue char(255)
)

无论您是否只在myvalue列中写入“a”或“hello world”,它都会在磁盘上保留 255 个字符的字符串空间。记住它。

于 2013-02-03T15:42:26.390 回答