本文介绍了在SQL语句结束时缺少分号(;)。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
//低于10行将图像转换为二进制数据
// below 10 lines convert image into binary data
byte[] FileByte = null;
//string filename = textBoxImage.Text.Substring(textBoxImage.Text.LastIndexOf("\\") + 1, textBoxImage.Text.Length - (textBoxImage.Text.LastIndexOf("\\") + 1));
string path = textBoxImage.Text;
FileStream fs = new FileStream(path, System.IO.FileMode.Open, System.IO.FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
long allbytes = new FileInfo(path).Length;
FileByte = br.ReadBytes((Int32)allbytes);
fs.Close();
fs.Dispose();
br.Close();
//Insert into access database
string connectionString = (@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Documents and Settings\nic-15\My Documents\test.accdb");
OleDbConnection con = new OleDbConnection(connectionString);
// cmd.Connection = con;
con.Open();
string query = "insert into arms_records values (thana,licence_number,sanction_date,licencee_name,father_name,dob,religion,caste,address,village,uid,mobile,email,arms_category,type_of_arm,no_of_arms,arms_number,valid_area,renewal_date,remark,image)"
+ " values (@thana, @lno, @sdate, @lname, @fname, @dob, @religion, @caste, @address, @village, @uid, @mobile, @email, @armscat, @toarm, @narms, @ano, @varea, @rdate, @remark, @image)";
OleDbCommand cmd = new OleDbCommand(query, con);
cmd.Parameters.AddWithValue("@thana", comboBoxthana.SelectedItem);
// (@thana, @lno, @sdate, @lname, @fname, @dob, @religion, @caste, @address, @village, @uid, @mobile, @email, @armscat, @toarm, @narms, @ano, @varea, @rdate, @remark, @image)
cmd.Parameters.AddWithValue("@lno", textBoxLicence_number.Text);
cmd.Parameters.AddWithValue("@sdate", dateTimePicker1.Value);
cmd.Parameters.AddWithValue("@lname", textBoxLicencee_Name.Text );
cmd.Parameters.AddWithValue("@fname", textBoxFatherName.Text);
cmd.Parameters.AddWithValue("@dob", dateTimePickerDob.Value);
cmd.Parameters.AddWithValue("@religion", comboBoxReligion.SelectedItem);
cmd.Parameters.AddWithValue("@caste", comboBoxCaste.SelectedItem);
cmd.Parameters.AddWithValue("@address", textBoxAdress.Text);
cmd.Parameters.AddWithValue("@village", textBoxvillage.Text);
cmd.Parameters.AddWithValue("@uid", textBoxUid.Text);
cmd.Parameters.AddWithValue("@mobile", textBox1Mobile.Text);
cmd.Parameters.AddWithValue("@email", textBoxemail.Text);
cmd.Parameters.AddWithValue("@armscat", comboBoxArmsCategory.SelectedItem);
cmd.Parameters.AddWithValue("@toarm", comboBoxtypeofarm.SelectedItem);
cmd.Parameters.AddWithValue("@narms", textBoxNoOfArm.Text);
cmd.Parameters.AddWithValue("@ano", textBoxArmsNo.Text);
cmd.Parameters.AddWithValue("@varea", comboBoxValidArea.SelectedItem);
cmd.Parameters.AddWithValue("@rdate", dateTimePickerRenewDate.Value);
cmd.Parameters.AddWithValue("@remark", textBoxRemark.Text);
cmd.Parameters.AddWithValue("@image", FileByte );
//cmd.Parameters.AddWithValue("@Im", fname); //alter as per your requirement
//cmd.Parameters.AddWithValue("@Img", FileBytes);
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show("Image insert successfully", "Insert Image into Access Database");
推荐答案
string query = "insert into arms_records values (...)"
+ " values (...)";
取出第一个,所以它是列名列表而不是一组值。
take out the first one, so it is the column names list instead of a set of values.
这篇关于在SQL语句结束时缺少分号(;)。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!