Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
VB NET-查询Mysql-在哪里\_Mysql_Vb.net_Double_Slash - Fatal编程技术网

VB NET-查询Mysql-在哪里\

VB NET-查询Mysql-在哪里\,mysql,vb.net,double,slash,Mysql,Vb.net,Double,Slash,我在mysql中找到了这段代码 Try MysqlConn.Close() MysqlConn.Open() Dim Query As String Query = "select id from foto where path = '" & TextBox5.Text & "'" COMMAND = New MySqlCommand(Query, MysqlConn) READER = COMMAND.ExecuteReader

我在mysql中找到了这段代码

Try
    MysqlConn.Close()
    MysqlConn.Open()
    Dim Query As String
    Query = "select id from foto where path = '" & TextBox5.Text & "'"
    COMMAND = New MySqlCommand(Query, MysqlConn)
    READER = COMMAND.ExecuteReader
    While READER.Read
        Dim sName = READER.GetString("id")
        TextBox6.Text = sName
    End While
Catch ex As Exception
    MessageBox.Show(ex.Message)
Finally
    MysqlConn.Dispose()
End Try
但糟糕的是,我想要的是
C:\my pic\myfile.jpg
(TextBox5.Text),mysql没有找到它。但是如果我试着像
C:\\my pic\\myfile.jpg
。如何在查询中使用
\\
(双斜杠)


感谢您的帮助………

尝试MySql.Data.MySqlClient.MySqlHelper.EscapeString()方法


您是否在问如何以编程方式添加/if only 1/?而不是从未选中的文本框输入创建查询,您应该使用一个参数。。。否则。至于您的问题:只需
TextBox5.Text.Replace(“\\”,“\\\\”)
就可以了。@JimmySmith我不确定MySqlCommand参数如何处理转义,所以我没有发布。@JimmySmith没有DV,但等待UV,直到最后编辑。可惜你删除了,因为它解决了OPs问题,并显示了命令参数的用法。我根本无意与你的答案相抗衡。我的评论只是想暗示DV的可能原因(来自其他人)。@JimmySmith标记为un-delete。很高兴这有助于解决问题@费尔伯特也感谢你的帮助。
Try
    MysqlConn.Close()
    MysqlConn.Open()
    Dim Query As String
    Query = "select id from foto where path = @PATH"
    COMMAND = New MySqlCommand(Query, MysqlConn)
    COMMAND.AddWithValue("@PATH",MySql.Data.MySqlClient.MySqlHelper.EscapeString(Textbox5.Text))
    READER = COMMAND.ExecuteReader
    While READER.Read
        Dim sName = READER.GetString("id")
        TextBox6.Text = sName
    End While
Catch ex As Exception
    MessageBox.Show(ex.Message)
Finally
    MysqlConn.Dispose()
End Try