任何人都可以对我的问题有所了解吗?我有这个表单代码,它应该获取文本框的文本并将其放入数据库中。但是,我遇到了一个错误,SqlException was unhandled by user code: String or binary data would be truncated. The statement has been terminated.
这是代码:
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
我已经阅读了许多类似我的问题和问题,但我不知道如何解决这个问题。