Solved

LAST RECORD IN SQL TABLE AND INCREMEMENT IN VB.NET

Posted on 2014-10-06
4
714 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 250 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 250 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

Salesforce Made Easy to Use

On-screen guidance at the moment of need enables you & your employees to focus on the core, you can now boost your adoption rates swiftly and simply with one easy tool.

Question has a verified solution.

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

Suggested Solutions

If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

726 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