2017-02-20 21 views
0

мой код:Использование постоянной внутренней части SQL запроса

Dim c3 As MySqlCommand 
    Dim q3 As String = "SELECT  date 
     FROM   `river-derwent-keswick-portinscale` 
    WHERE(`date` = Input)" 
    c3 = New MySqlCommand(q3, conn) 
    'c3.Parameters.AddWithValue("@Date", Userinput.Text) 
    'Userinput.Text Is a textbox 
    ' If a field if found where the date matches the userinput 
    ' Output value to textbox 
    Dim DR3 As MySqlDataReader = c3.ExecuteReader() 
    If DR3.Read Then 
     Datetxt.Text = DR3.GetValue(0) 
    End If 
    DR3.Close() 

При этом используется предустановленный константу глобальной переменной, установленной внутри другой формы, которая подается на вход, где вход = TextBox1.Text. Это означает, что пользователь вводит значение в textbox1.text, тогда это значение устанавливается как Input. Может ли кто-нибудь помочь мне в том, как использовать эту константу для запроса с помощью инструкции Where.

ответ

0

Вы почти получили его в прокомментированном коде. Измените запрос, чтобы принять дату аргумент:

SELECT date 
FROM `river-derwent-keswick-portinscale` 
WHERE(`date` = @date_param) 

Затем добавить параметр в команде

c3.Parameters.AddWithValue("@date_param", Userinput.Text) 
0
Dim c3 As MySqlCommand 
Dim q3 As String = "SELECT date FROM `river-derwent-keswick-portinscale` WHERE(`date` = @Date)" 
c3 = New MySqlCommand(q3, conn) 
c3.Parameters.AddWithValue("@Date", Userinput.Text) 
'Userinput.Text Is a textbox 
' If a field if found where the date matches the userinput 
' Output value to textbox 
Dim DR3 As MySqlDataReader = c3.ExecuteReader() 
If DR3.Read Then 
    Datetxt.Text = DR3.GetValue(0) 
End If 
DR3.Close()