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

x
?
Solved

LAST RECORD IN SQL TABLE AND INCREMEMENT IN VB.NET

Posted on 2014-10-06
4
Medium Priority
?
816 Views
Last Modified: 2014-10-15
i CREATED A INSERT FOR 3 SPORTS DRAFT THERE IS A pk that's is the primary key. So I thought PLAYERID WAS PRMARY KEY SO LOOK AT THIS LAST TWO RECORDS IF aI only called last record and++
sql table
Anyone know a quick easy way to increment txtPLAYERid.text
    End Sub
    Public Sub NBAcheckInsert()

        Dim strRound As String = CStr(txtRound.Text)
        Dim strdraftyear As String = CStr(txtDraftYear.Text)
        Dim strdraftteamID As String = CStr(txtDraftteam.Text)
        Dim strOrigteamID As String = CStr(txtorigteamID.Text)
        Dim strtxtOverallP As String = CStr(txtOverallP.Text)
        Dim strDraftPos As String = CStr(txtDPosition.Text)
        Dim strsportscode As String = CStr(cmbSport.ValueMember)
        Dim query As String = String.Empty

        Using conn As New SqlConnection("Data Source=tsnappdev01;Initial Catalog=TSN2;User ID=sa;Password=sportsrus")

            Using comm As New SqlCommand()
                With comm
                    .Connection = conn
                    .CommandType = CommandType.Text



                    .Parameters.AddWithValue("@round", strRound)
                    .Parameters.AddWithValue("@draftyear", strdraftyear)
                    .Parameters.AddWithValue("@DraftteamID", strdraftteamID)
                    .Parameters.AddWithValue("@OrigTeamID", strOrigteamID)
                    .Parameters.AddWithValue("@Overallpos", strtxtOverallP)
                    .Parameters.AddWithValue("@Draftpos", strDraftPos)
                    .Parameters.AddWithValue("@sportcode", strsportscode)
                    query &= "INSERT INTO Draft(round, draftyear,"
                    query &= "DraftteamID,OrigTeamID,Overallpos,Draftpos,sportcode)"
                    query &= "VALUES (@round,@draftyear,@DraftteamID,@OrigTeamID,@Overallpos,@Draftpos,@sportcode)"
                    .CommandText = query
                End With
                Try
                    conn.Open()
                    comm.ExecuteNonQuery()
                Catch ex As SqlException
                    MsgBox(ex.Message & ex.StackTrace & ex.ToString)
                    Exit Sub
                End Try
                conn.Close() 
                Reset()
            End Using
        End Using

    End Sub

Open in new window

There is my insert I can't think of a way if the cells are empty how to grab last playerID AND INCREMENT


HERE



WAHT i got

appearance of app
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
4 Comments
 

Assisted Solution

by:powerztom
powerztom earned 0 total points
ID: 40364683
Just need last PlayerID IN DATABASE AND INCREMENT++ SO NO DUPLICATES
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 1000 total points
ID: 40364735
Create a second query SELECT MAX(PlayerID) FROM Draft.

This will return the highest PlayerID in your table. Increment and pass it as a parameter to your INSERT command.
0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 1000 total points
ID: 40365612
Or you can use an Identity column which will increment automatically whenever you insert a new row.
0
 

Author Closing Comment

by:powerztom
ID: 40381718
nICE WORK GUYS
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

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