Link to home
Start Free TrialLog in
Avatar of Tom Powers
Tom Powers

asked on

sql query

I have a query and the parameter part I can't get it correct.this is in a win form VB.NET
 Public Sub PlayerID()
        Dim connetionString As String
        Dim connection As SqlConnection
        Dim adapter As SqlDataAdapter
        'Dim PlayerID As Integer = CInt(txtplayerID.Text)
        connetionString = "Data Source=tsnappdev01;Initial Catalog=TSN2;User ID=sa;Password=XXXXXXXXX"
        Sql = "SELECT p.PK,p.Sportcode, p.FirstName, p.LastName, p.Position, Teams.Fullname,p.hotcold,"
        Sql += " p.Description,p.Insight, p.TeamID, p.PlayerID, p.Date, p.Status"
        Sql += " FROM playernotes p Join Teams ON Teams.TeamID = p.TeamID WHERE p.Sportcode='" & Sportscode & "' " And p.PlayerID = " txtplayerid.Text"
        connection = New SqlConnection(connetionString)
        DataGridView1.DataSource = Nothing
        DataGridView1.ClearSelection()

        Dim ds1 = New DataSet

        Try
            connection.Open()
            adapter = New SqlDataAdapter(Sql, connection)
            adapter.Fill(ds1)
            connection.Close()
            DataGridView1.DataSource = ds1.Tables(0)
            DataGridView1.Refresh()
        Catch ex As Exception
            MsgBox(Sql)
        End Try
        Me.DataGridView1.RowsDefaultCellStyle.BackColor = Color.Bisque
        Me.DataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige
        DataGridView1.ColumnHeadersHeight = 55
        DataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize
        ' Add the image column to the grid.
        ' DataGridView1.Columns.Add(imageCol)

        '  DataGridView1.Columns("Lastname").Frozen = False
        DataGridView1.Columns("Lastname").Frozen = True

    End Sub

Open in new window


THE p.PlayerID = txtPlayerID.Text I'm passing the txtPlayerid.text from another form and form with notes accepts Playerid value in load statement
ASKER CERTIFIED SOLUTION
Avatar of AndyAinscow
AndyAinscow
Flag of Switzerland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Tom Powers
Tom Powers

ASKER

I've requested that this question be deleted for the following reason:

Figured it out after some trial and error

connetionString = "Data Source=tsnappdev01;Initial Catalog=TSN2;User ID=sa;Password=sportsrus"
        Sql = "SELECT p.PK,p.Sportcode, p.FirstName, p.LastName, p.Position, Teams.Fullname,p.hotcold,"
        Sql += " p.Description,p.Insight, p.TeamID, p.PlayerID, p.Date, p.Status"
        Sql += " FROM playernotes p Join Teams ON Teams.TeamID = p.TeamID WHERE p.Sportcode='" & Sportscode & "'  And p.PlayerID = '" & txtplayerID.Text & "'"
Thanks Cous I figured this one and what you where saying was the problem