Solved

sql query

Posted on 2014-11-19
3
187 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
  • 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
kill process lock Sql server 9 45
C# Object Reference is Required for the non-static field, method, or property 10 32
C# bracket error 3 30
Error handling in asp.net site 5 23
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…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

813 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now