Solved

sql query

Posted on 2014-11-19
3
200 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 500 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

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

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

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

626 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