任何人都可以對我的問題投下一些光?我有這個表單代碼,它應該把文本框的文本放到數據庫中。我,然而,得到一個錯誤,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
我讀過許多問題和問題,如我的,但我沒有任何線索,我怎麼可能會解決這個問題。
我已經做到了,但在aspx頁面中,但我認爲你建議我在.vb文件中也這樣做?例如:Dim iDUsuario As String = RFC.ToString(0,50) – DarkVader
它是引用的任何地方,您可以限制長度......您還可以增加數據庫允許的長度。 – Haney