当我写这行时:
SqlCommand MySqlCommand = new SqlCommand("INSERT INTO [User](NAME ,PASSWORD ,PUBLISH_FOLDER,ACTIVE,IP,PORT) Values ('shula','Aa1234','study','true','1015','8080')", MyConnection);
它有效,但是当我写这行时:
string Name = user.Name;
string Password = user.Password;
string Port = (user.Port).ToString();
string publishFolder=user.publishFolder;
string Ip=user.Ip;
SqlCommand MySqlCommand = new SqlCommand("INSERT INTO [User](NAME ,PASSWORD ,PUBLISH_FOLDER,ACTIVE,IP,PORT) Values (" + Name + "," + Password + "," + publishFolder + ",TRUE," + Ip + "," + Port + ")", MyConnection);
错误是:
列名无效......
答案 0 :(得分:1)
这是因为
" Values (" + Name + ","
生成
Values (shula,
而不是
Values ('shula',
但是你不应该添加'
,而是使用参数。