Avatar of Tom Powers
Tom Powers
 asked on

insert statement from vb.net 2013

Hey Ya ,

I'm stuck on and Insert statement tried numerous trouble shooting I firest fixed missing character in the statement then I realized I forgot the date now I cast to cdate(txtDate.text) I get an error with smalldatetime.

here is the insert statement
 Public Sub Insertdata()
        Dim strSportsCode As String = Sportscode
        Dim strFirstName As String = CStr(txtFname.Text)
        Dim strLastname As String = CStr(txtLname.Text)
        Dim strPosition As String = CStr(cmbpos.Text)
        Dim strDate As Date = CDate(txtDate.Text)
        Dim strHotCold As String = CStr(txtHotCold.Text)
        Dim strDescription As String = CStr(txtdes.Text)
        Dim strInsight As String = CStr(txtInsight.Text)
        Dim strTeamID As String = CStr(txtTeamID.Text)
        Dim strPlayerID As Integer = CInt(txtplayerID.Text)
        Dim strStatus As String = CStr(cmbstatus.Text)
       
        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("@Sportcode", strSportsCode)
                    .Parameters.AddWithValue("@FirstName", strFirstName)
                    .Parameters.AddWithValue("@LastName", strLastname)
                    .Parameters.AddWithValue("@Position", strTeamID)
                    .Parameters.AddWithValue("@HotCold", strHotCold)
                    .Parameters.AddWithValue("@Description", strDescription)
                    .Parameters.AddWithValue("@Date", strInsight)
                    .Parameters.AddWithValue("@Insight", strInsight)
                    .Parameters.AddWithValue("@TeamID", strTeamID)
                    .Parameters.AddWithValue("@PlayerID", strPlayerID)
                    .Parameters.AddWithValue("@Status", strStatus)
                    
                    query &= "INSERT INTO PlayerNotes (Sportcode, FirstName,"
                    query &= "LastName,Position,HotCold,Description,Date,Insight,TeamID,PlayerID,Status)"
                    query &= "VALUES (@Sportcode,@FirstName,@LastName,@Position,@HotCold,@Description,@Date,@Insight,@TeamID,@PlayerID,@Status)"

                    .CommandText = query
                End With
                Try
                    conn.Open()
                    comm.ExecuteNonQuery()
                    MessageBox.Show("Record Added!")
                    conn.Close()
                Catch ex As SqlException
                    MessageBox.Show(ex.Message & ex.StackTrace & ex.ToString)


                End Try

                '  txtPlayerID.Visible = True
                
            End Using
        End Using
    End Sub

Open in new window

conversion failed date and time
error message
Microsoft SQL Server 2005Visual Basic.NET.NET Programming

Avatar of undefined
Last Comment
Tom Powers

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Jerry Miller

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Tom Powers

ASKER
That fixed it good eye
Jerry Miller

Sometimes it helps just to have fresh eyes look at an issue. We get trained to see what we think is there, but someone coming in will notice a typo or copy/paste error almost immediately.

I have looked at something for an hour or so to have one of my partners walk up and go 'you have a typo on line 5, fix that and your error goes away'. It drives me nuts, but at least someone sees it.
Tom Powers

ASKER
Thanks Jerry
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy