Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

sql query

Posted on 2014-11-19
3
Medium Priority
?
201 Views
Last Modified: 2014-11-19
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
0
Comment
Question by:powerztom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 44

Accepted Solution

by:
AndyAinscow earned 2000 total points
ID: 40452748
put a breakpoint on your line 10: connection = New SqlConnection(connetionString)
Now have a look at the contents of the string sql.  I suspect you have one or more quote marks in the wrong place.
0
 

Author Comment

by:powerztom
ID: 40452814
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 & "'"
0
 

Author Closing Comment

by:powerztom
ID: 40452815
Thanks Cous I figured this one and what you where saying was the problem
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

704 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question