【发布时间】:2013-04-17 04:01:51
【问题描述】:
我花了几个小时试图解决这个错误,但我做不到。如果有人能帮我解决这个问题,我会很高兴。
代码:
FileStream fs;
fs = new FileStream(@imagename, FileMode.Open, FileAccess.Read);
byte[] picbyte = new byte[fs.Length];
fs.Read(picbyte, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
string query;
SqlCeConnection conn = new SqlCeConnection(@"Data Source=C:\Users\admin\documents\visual studio 2010\Projects\WindowsFormsApplication1\WindowsFormsApplication1\hotel.sdf");
conn.Open();
SqlParameter picparameter = new SqlParameter();
picparameter.SqlDbType = SqlDbType.Image;
picparameter.ParameterName = "pic";
picparameter.Value = picbyte;
query = "insert into Staffs(name, age, qualification, mobile, landline, salary, salary_type, address, work_type, reference, picture) values(" + textBox16.Text + ", " + textBox15.Text + "," + textBox14.Text + "," + textBox13.Text + "," + textBox12.Text + "," + textBox11.Text + "," + comboBox2.Text + "," + richTextBox2.Text + "," + textBox10.Text + "," + textBox9.Text + ", " + " @pic)";
SqlCeCommand cmd = new SqlCeCommand("insert into Staffs(name, age, qualification, mobile, landline, salary, salary_type, address, work_type, reference, picture) values(" + textBox16.Text + ", " + textBox15.Text + "," + textBox14.Text + "," + textBox13.Text + "," + textBox12.Text + "," + textBox11.Text + "," + comboBox2.Text + "," + richTextBox2.Text + "," + textBox10.Text + "," + textBox9.Text + ", " + " @pic)", conn);
cmd.ExecuteNonQuery();
MessageBox.Show("Profile Added");
cmd.Dispose();
conn.Close();
conn.Dispose();
错误:
列名无效节点名(如果有)=,列名=d
到目前为止我发现了什么:
“column name = d”中的错误是文本字段的值。如果我在文本字段中输入 a,错误将变为“列名 = a”。
如果我在文本字段中输入数字而不是字符,则错误会变为此 "缺少一个参数[参数序号 = 1]。列的数据类型是 nvarchar。
我尝试编辑数据库架构,但没有任何反应。
我检查了数据库的重复副本,但没有找到,所以我认为问题出在代码上。
列的数据类型为 nvarchar、int 或 image。
为了确保我检查了数据库以查看插入是否有效,数据库仍然是空的。
【问题讨论】:
-
我已经编辑了你的标题。请参阅“Should questions include “tags” in their titles?”,其中的共识是“不,他们不应该”。
-
您还应该将您的
FileStream、SqlCeConnection和SqlCeCommand放入using块中。
标签: c# sql-server-2008 sql-insert