Quantcast
Channel: VBForums
Viewing all articles
Browse latest Browse all 15549

VS 2019 [RESOLVED] Issue while inserting a row to SqlDB

$
0
0
Hello,

Am getting "String or binary data would be truncated. The statement has been terminated " error msg while trying to insert a row in Sql Db.

Any suggestions will be most welcome..

thanks

Code:

  Public Sub InsertData()

        Try

            Dim myAppName As String = "myAppName"
            Dim myADName As String = "myADName"
            Dim myStatus As String = "myStatus"

            Using myConn As New SqlConnection

                myConn.ConnectionString = myConnStr
                myConn.Open()

                Using myCmd As New SqlCommand
                    myCmd.Connection = myConn

                    Dim myQuery As String = "INSERT INTO " & myTableName &
                                            "(" &
                                                clsConst.AppName & "," &
                                                clsConst.AdUserName & "," &
                                                clsConst.RStatus &
                                            ") " &
                                              "VALUES (" &
                                                    "'" & myAppName & "', " &
                                                    "'" & myADName & "', " &
                                                    "'" & myStatus & "'" &
                                                ")"


                    myCmd.CommandText = myQuery
                    myCmd.ExecuteNonQuery()

                    myConn.Close()

                End Using


            End Using


        Catch ex As Exception
            MessageBox.Show(ex.Message)
        End Try



    End Sub


Viewing all articles
Browse latest Browse all 15549

Trending Articles