Solved

LAST RECORD IN SQL TABLE AND INCREMEMENT IN VB.NET

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

Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

624 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