不允许从数据类型 varchar 到 varbinary 的隐式转换

implicit conversion from data type varchar to varbinary is not allowed(不允许从数据类型 varchar 到 varbinary 的隐式转换)
本文介绍了不允许从数据类型 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 的隐式转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
Hibernate reactive No Vert.x context active in aws rds(AWS RDS中的休眠反应性非Vert.x上下文处于活动状态)
Bulk insert with mysql2 and NodeJs throws 500(使用mysql2和NodeJS的大容量插入抛出500)
Flask + PyMySQL giving error no attribute #39;settimeout#39;(FlASK+PyMySQL给出错误,没有属性#39;setTimeout#39;)
auto_increment column for a group of rows?(一组行的AUTO_INCREMENT列?)
Sort by ID DESC(按ID代码排序)