在插入查询中获取错误以在C#中存储文件的路径 [英] getting error in insert query to store path of a file in c#

查看:67
本文介绍了在插入查询中获取错误以在C#中存储文件的路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

im在备忘录类型的访问字段中存储诸如"c:/images/Winter9.jpg"之类的文件名
但它给出了错误

 comm.CommandText = "  + "  + comboBox1.Text + "  + comboBox2.Text + " ','" + comboBox3.Text +  ', '" + textBox1.Text +  ',' + file [ 0 ] + "  + count + " ;
                   comm.Connection = conn;
                   conn.Open();
                   comm.ExecuteNonQuery();
                   conn.Close(); 


这里的文件[0]是字符串,它不能正常工作,请帮忙!!!!!!!!!!!!!!使用未经验证的用户输入进行字符串连接.曾经!!至少要使用参数化查询.

也许我误解了这个问题,但是,如果您假设给定文件名,SQL Server会自动将文件的内容插入数据库中,那么您就错了.

请参见此处 [
担心 !!!!怎么做呢?使用F11进行跟踪.希望这能解决您的问题.

如果该解决方案不起作用,请对此解决方案发表评论.


im storing a file name like "c:/images/Winter9.jpg" in access field which is of memo type
but it gives error

comm.CommandText = "Insert into one_mark" + " (class,subject,chapter_name,question,image,id)values('" + comboBox1.Text + "','" + comboBox2.Text + "','" + comboBox3.Text + "','" + textBox1.Text + "','" + file[0] + "','"+count+"')";
                   comm.Connection = conn;
                   conn.Open();
                   comm.ExecuteNonQuery();
                   conn.Close();


here file[0] is string and it is not working plz help guys!!!!!!!!!!!

One, you should not be using string concatenation with unvalidated user input. EVER!! Use a parameterized query at the very least.

Perhaps I misunderstood the question, but, if you are assuming that given a filename SQL Server will automatically insert the contents of the file to the database then you are mistaken.

See
here[^] for how to add files to SQL Server


Dear Member,

The problem is with your file[0]''s value. Check for verbatim. File Path should be like "C:\...", but in program it gets values like "C:\\...". So, check that first.

Worried !!!! How to do so? Go for Tracing with F11. Hope this will resolve your issue.

If the solution does not work, please comment on this solution.


这篇关于在插入查询中获取错误以在C#中存储文件的路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆