我花了几个小时试图解决这个错误,但我做不到。如果有人能帮我解决这个问题,我会很高兴。
代码:
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。
只是为了确保我检查了数据库以查看插入是否有效,数据库仍然是空的。