Solved

insert statement from vb.net 2013

Posted on 2014-12-01
4
279 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
[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
  • 2
4 Comments
 
LVL 18

Accepted Solution

by:
Jerry Miller earned 500 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

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

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

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
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…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

756 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