Solved

insert statement from vb.net 2013

Posted on 2014-12-01
4
283 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

Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

Question has a verified solution.

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

Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
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.
In this video, viewers are given an introduction to using the Windows 10 Snipping Tool, how to quickly locate it when it's needed and also how make it always available with a single click of a mouse button, by pinning it to the Desktop Task Bar. Int…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …

636 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