VB NET - 查询 Mysql - 哪里是 \
VB NET - Query Mysql - where is \
我有这段代码可以在 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() 方法。
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
我有这段代码可以在 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() 方法。
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