Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to Use a parameter within SQL in Vb 2010 (web developer)
    text
    copied!<p>I am trying to work out <code>SQL</code> code in <code>VB</code> but I am having problems I have a simple database with the table admin with the columns <code>UserName</code> and <code>Password</code>.</p> <p>I want to be able to read data from a text box and then input it into a SQL string&hellip; the SQL string works (I've tested it) and I can get it to output with a simple <code>SELECT</code> statement but I can't seem to get the SQL to read my Parameter.</p> <p>Help?</p> <pre><code>Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click Call Password_Check(txtTestInput.Text) End Sub Public Sub Password_Check(ByVal Answer As String) Dim con As New SqlConnection Dim cmd As New SqlCommand Dim parameter As New SqlParameter("@Username", Answer) Try con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("Database1ConnectionString1").ConnectionString con.Open() cmd.Connection = con cmd.CommandText = " SELECT Password FROM Admin WHERE (UserName = @Username)" cmd.Parameters.Add(parameter) Dim lrd As SqlDataReader = cmd.ExecuteReader() While lrd.Read() Dim sothing As String sothing = lrd("Password").ToString If lrd("Password").ToString = txtPassword.Text Then lblTestData.Text = "passwordSuccess" ElseIf lrd("Password").ToString &lt;&gt; txtPassword.Text Then lblTestData.Text = "passwordFail...:(" End If End While Catch ex As Exception lblTestData.Text = "Error while retrieving records on table..." &amp; ex.Message Finally con.Close() End Try End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload