【发布时间】:2018-03-24 01:46:28
【问题描述】:
我将SQL语句放入可视化按钮中,使其在数据库中插入数据,当我触摸它时,会发生此错误:
从字符串“插入 TBL_Usuario_102 值”到类型“Double”的转换无效。
这是按钮中的代码:
Private Sub Guardar_Click(sender As Object, e As EventArgs) Handles Guardar.Click
If NombreDePersona.Text <> "" And Cedula.Text <> "" And RepetirContraseña.Text <> "" And Contraseña.Text <> "" Then
If (RepetirContraseña.Text = Contraseña.Text) Then
instruccionSQL = New SqlClient.SqlCommand("Insert into TBL_Usuario_102 values" +
"(" + Cedula.Text + "," +
NombreDePersona.Text + "," + 3 +
"," + Contraseña.Text + "," +
FechaInclusion.Text + "," + 0 +
"," + FechaInclusion.Text + "," + 3 + ")")
MsgBox("Datos Guardados Correctamente")
Cedula.Clear()
NombreDePersona.Clear()
Contraseña.Clear()
RepetirContraseña.Clear()
Else
MsgBox("Las contraseñas no coinciden")
End If
Else
MsgBox("Escriba en Cada Campo")
End If
End Sub
SQL 连接在一个模块中,它运行良好,因为当我在 SQL Server 中手动插入数据时,登录工作正常。
数据库的表中数据的类型是这样的
- varchar(15)
- varchar(20)
- int
- varchar(50)
- 日期时间
- 位
- 日期时间
- int
【问题讨论】:
-
1.您的代码对 Sql Injection hacking 完全开放。 2. 开启
Option Strict。 3. VB.Net 的连接运算符是&而不是+。因为您的代码中有+ 3 +,VB 可能会尝试隐式尝试将其转换为数字形式,从而导致您的错误。 -
这个问题可能是由于在字符串和数字之间使用'+'运算符(例如3)尝试使用字符串连接运算符&或字符串“3”
标签: sql-server vb.net visual-studio visual-studio-2017