implicit conversion from data type varchar to varbinary is not allowed(不允许从数据类型 varchar 到 varbinary 的隐式转换)
问题描述
在我运行程序后,我添加了数据,然后我收到了这条消息:
After I run the program, I add the data, and then i get this message:
不允许从数据类型 varchar 隐式转换为 varbinary
implicit conversion from data type varchar to varbinary is not allowed
我和我在 YouTube 上观看了这个视频和youtuber完全一样.这对他有效,但对我无效.
I watched this video on YouTube and I did exactly the same as youtuber. It works for him but not me.
我正在尝试将 Visual Studio 中的数据添加到 SQL 数据库中:
I am trying to add data from Visual studio into an SQL database:
代码如下:
Imports System.Data.SqlClient
SELECT CONVERT(varchar(100), CONVERT(varbinary(max),'0xFFD8FFE000'))
Public Class Form1
Dim Conn As SqlConnection
Dim CMD As SqlCommand
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Conn = New SqlConnection
Conn.ConnectionString = "Data Source=BYG-A101-MOELKA;Initial Catalog=App;Integrated Security=True"
Dim READER As SqlDataReader
Try
Conn.Open()
Dim Query As String
Query = "insert into person (ID,firstname,lastname,age) values ('" & TextBox1.Text & "', '" & TextBox2.Text & "', '" & TextBox3.Text & "', '" & TextBox4.Text & "')"
CMD = New SqlCommand(Query, Conn)
READER = CMD.ExecuteReader
MessageBox.Show("Datasaved")
Conn.Close()
Catch ex As Exception
MessageBox.Show(ex.Message)
Finally
Conn.Dispose()
End Try
End Sub
推荐答案
一些问题
ExecuteReader 不应用于插入
使用 ExecuteNonQuery一个>
ExecuteReader should not be used for an insert
use ExecuteNonQuery
这会受到注入攻击.使用参数.参数必须与表列的数据类型匹配.
That is subject to injection attack. Use parameters. The parameters must match the data type of the table columns.
这篇关于不允许从数据类型 varchar 到 varbinary 的隐式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:不允许从数据类型 varchar 到 varbinary 的隐式转换


- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 更改自动增量起始编号? 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01