必须声明标量变量

必须声明标量变量

本文介绍了必须声明标量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我正在尝试修复此错误。请帮忙。



我收到以下错误并且没有插入数据:

必须声明标量变量 @bytImage。



Hello,

I am trying to fix this bug. Please help.

I am getting below error and no data inserted :
"Must declare the scalar variable "@bytImage"."

Public Sub InsertFile()
    Dim sMainFolder As String = "D:\Project"
    Dim conAccess As Data.OleDb.OleDbConnection
    Dim commSQL As Data.OleDb.OleDbCommand = New Data.OleDb.OleDbCommand()
    Dim bytImage As Byte()
    Dim QueryParameter As New Data.OleDb.OleDbParameter
    QueryParameter.DbType = Data.DbType.Binary

    Try
        If Me.fulFileUpload.HasFile = True Then
            bytImage = Me.fulFileUpload.FileBytes
            QueryParameter.Value = bytImage

            conAccess = New Data.OleDb.OleDbConnection
            conAccess.ConnectionString = "File Name=" & sMainFolder & "\" & "Project.udl"
            conAccess.Open()
            commSQL.Connection = conAccess
            commSQL.CommandText = "INSERT INTO [PICS] ([IMAGE]) VALUES (@bytImage))"

            ' ''QueryParameter = commSQL.Parameters.Add("@bytImage", Data.OleDb.OleDbType.Binary)
            ' ''QueryParameter.Direction = Data.ParameterDirection.Input
            ' ''commSQL.Parameters.Add(QueryParameter)
            commSQL.Parameters.AddWithValue("@bytImage", bytImage)

            commSQL.ExecuteNonQuery()
            conAccess.Close()
            commSQL.Dispose()
        End If
    Catch ex As Exception
        'ex.Message = "Must declare the scalar variable "@bytImage"."
    End Try
End Sub





提前谢谢,

~Goutam



Thank you in advance,
~ Goutam

推荐答案

commSQL.CommandText = "INSERT INTO [PICS] ([IMAGE]) VALUES (?)"


DECLARE @DateFormat INT

SET @DateFormat = 0
WHILE @DateFormat < 15
BEGIN
    PRINT CONVERT(VARCHAR(30), GETDATE(), @DateFormat)
    SET @DateFormat = @DateFormat + 1
END

SET @DateFormat = 100
WHILE @DateFormat < 115
BEGIN
    PRINT CONVERT(VARCHAR(30), GETDATE(), @DateFormat)
    SET @DateFormat = @DateFormat + 1
END
GO


这篇关于必须声明标量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-27 19:38