运行程序后,我添加数据,然后收到此消息:
不允许从数据类型varchar到varbinary的隐式转换
我在YouTube上观看了此video,而且我和youtuber完全一样。它适用于他,但不适用于我。
我正在尝试将Visual Studio中的数据添加到SQL数据库中:
以下是代码:
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
答案 0 :(得分:1)