Can anyone cast some light on my problem? I have this form code and which is supposed to take the text of the textbox and put it in the database. I am, however, getting an error, SqlException was unhandled by user code: String or binary data would be truncated. The statement has been terminated.
Here is the code:
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Partial Class Usuarios
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub BotonA_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim iDUsuario As String = RFC.ToString
Dim nomUsuario As String = Name.ToString
Dim apellidoP As String = ApellidoPaterno.ToString
Dim apellidoM As String = ApellidoMaterno.ToString
Dim passUsuario As String = contrasena.ToString
Dim nombre As String = seudonimo.ToString
Dim iDtipo As Integer = "1"
Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)
con.Open()
Dim cmd As New SqlCommand("INSERT INTO usuarios (iDUsuario, nomUsuario, apellidoP, apellidoM, passUsuario, nombre, idTipo) VALUES (@iDUsuario, @nomUsuario, @apellidoP, @apellidoM, @passUsuario, @nombre, @iDtipo)", con)
cmd.Parameters.AddWithValue("@iDUsuario", iDUsuario)
cmd.Parameters.AddWithValue("@nomUsuario", nomUsuario)
cmd.Parameters.AddWithValue("@apellidoP", apellidoP)
cmd.Parameters.AddWithValue("@apellidoM", apellidoM)
cmd.Parameters.AddWithValue("@passUsuario", passUsuario)
cmd.Parameters.AddWithValue("@nombre", nombre)
cmd.Parameters.AddWithValue("@iDtipo", iDtipo)
cmd.ExecuteNonQuery()
End Sub
End Class
I've read many questions and problems like mine but I haven't any clue how I might resolve this.