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

x
?
Solved

insert statement from vb.net 2013

Posted on 2014-12-01
4
Medium Priority
?
291 Views
Last Modified: 2014-12-02
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
0
Comment
Question by:powerztom
  • 2
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 2000 total points
ID: 40474667
Parameters.AddWithValue("@Date", strInsight) on line 31 should be
Parameters.AddWithValue("@Date", strDate )
0
 

Author Closing Comment

by:powerztom
ID: 40476211
That fixed it good eye
0
 
LVL 18

Expert Comment

by:Jerry Miller
ID: 40476360
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.
0
 

Author Comment

by:powerztom
ID: 40476588
Thanks Jerry
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Hello there! As a developer I have modified and refactored the unit tests which was written by fellow developers in the past. On the course, I have gone through various misconceptions and technical challenges when it comes to implementation. I would…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

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