SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Parameterized Query

    Hi, I am a complete newbie ..and was following a bit of code in the excellent build your own ASP.NET 3.5 website, that shows you how to use parametrized queries.
    I would like the user to find a specific name, instead of a ID, I have tried this but its not bringing up any data, can anyone help...many thanks

    Paul

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
    Dim conn As SqlConnection
    Dim comm As SqlCommand
    Dim reader As SqlDataReader
    Dim reader2 As SqlDataReader


    conn = New SqlConnection("Server=localhost\SqlExpress;" & _
    "Database = Test;Integrated Security=True")

    comm = New SqlCommand( _
    "Select NamesID, Names, Surnames from Allnames where Names = @Names", conn)
    Dim Names As String ----not sure string is right!


    comm.Parameters.Add("@Names", System.Data.SqlDbType.NVarChar, 50)
    comm.Parameters("@Names").Value = Names error here(name is used before it has bebn assigned a value)
    Try
    conn.Open()
    reader2 = comm.ExecuteReader()
    myRepeater.DataSource = reader2
    myRepeater.DataBind()
    reader2.Close()
    reader = comm.ExecuteReader()
    If reader.Read() Then
    userlabel.Text = "Name ID: " & _
    reader.Item("NamesID") & "<br/>" & _
    "Name: " & reader.Item("Names") & "<br/>" & _
    "Surname: " & reader.Item("Surnames")



    End If
    reader.Close()

    Catch
    userlabel.Text = "Error retrieving user data"
    Finally
    conn.Close()
    End Try

    'End If

    End Sub

  2. #2
    SitePoint Addict
    Join Date
    Feb 2005
    Location
    Clogland
    Posts
    322
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try
    Code VBNET:
    Dim Names As String = "john"
    or better yet, add a TextBox to your page, and then use
    Code VBNET:
    comm.Parameters("@Names").Value = TextBox1.Text

  3. #3
    SitePoint Member
    Join Date
    May 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks very much..it work!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •