Solved

LAST RECORD IN SQL TABLE AND INCREMEMENT IN VB.NET

Posted on 2014-10-06
4
632 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
  • 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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
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…

708 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

18 Experts available now in Live!

Get 1:1 Help Now