Solved

insert statement from vb.net 2013

Posted on 2014-12-01
4
268 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 500 total points
Comment Utility
Parameters.AddWithValue("@Date", strInsight) on line 31 should be
Parameters.AddWithValue("@Date", strDate )
0
 

Author Closing Comment

by:powerztom
Comment Utility
That fixed it good eye
0
 
LVL 18

Expert Comment

by:Jerry Miller
Comment Utility
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
Comment Utility
Thanks Jerry
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

771 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

16 Experts available now in Live!

Get 1:1 Help Now