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 的隐式转换
基础教程推荐
- 带有WHERE子句的LAG()函数 2022-01-01
- 带更新的 sqlite CTE 2022-01-01
- while 在触发器内循环以遍历 sql 中表的所有列 2022-01-01
- MySQL根据从其他列分组的值,对两列之间的值进行求和 2022-01-01
- 使用 VBS 和注册表来确定安装了哪个版本和 32 位 2021-01-01
- MySQL 5.7参照时间戳生成日期列 2022-01-01
- ORA-01830:日期格式图片在转换整个输入字符串之前结束/选择日期查询的总和 2021-01-01
- CHECKSUM 和 CHECKSUM_AGG:算法是什么? 2021-01-01
- 如何在 CakePHP 3 中实现 INSERT ON DUPLICATE KEY UPDATE aka upsert? 2021-01-01
- 从字符串 TSQL 中获取数字 2021-01-01
