Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

LAST RECORD IN SQL TABLE AND INCREMEMENT IN VB.NET

Posted on 2014-10-06
4
Medium Priority
?
834 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 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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to shrink a transaction log file down to a reasonable size.
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…

926 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