Solved

sql query

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

In SQL Server, when rows are selected from a table, does it retrieve data in the order in which it is inserted?  Many believe this is the case. Let us try to examine for ourselves with an example. To get started, use the following script, wh…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

744 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

11 Experts available now in Live!

Get 1:1 Help Now