gpt4 book ai didi

c# - 错误 - 必须声明标量变量 - C#

转载 作者:太空宇宙 更新时间:2023-11-03 11:46:22 24 4
gpt4 key购买 nike

<分区>

我正在使用 C# 实现将文件上传到文件夹的功能。它发生错误,错误是“单击上传后必须声明标量变量“@TABLE_ID”。我做了一些研究并尝试使用其他示例,但错误仍然发生。这是上传功能:

protected void UploadFile(object sender, EventArgs e)
{
string str = ConfigurationManager.ConnectionStrings["Ulysses"].ConnectionString;
string filenam = FileUpload1.FileName.ToString();
string TABLE_NAME = "REQUEST";

int table_id = -1;
table_id = generateNextId("SP_LINK_TABLE_FIELD_ID");

string path = @"C:\Users\muhd\Documents\CyberLink";

path = path + filenam;
FileUpload1.PostedFile.SaveAs(path);

SqlConnection con = new SqlConnection(str);
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "Insert into OLE(LINK_TABLE_ID, LINK_TABLE_NAME, OLE_LINK_FILE_NAME) values(@TABLE_ID,@TABLE_NAME,@FILE_NAME)";
cmd.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@TABLE_ID", SqlDbType.Int).Value = table_id;
command.Parameters.AddWithValue("@TABLE_NAME", TABLE_NAME);
command.Parameters.AddWithValue("@FILE_NAME",path);
cmd.Connection = con;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}

table_id 是使用另一个函数从存储过程中获取的。请引用以下内容:

protected int generateNextId(string strStoredProcedureName)//this is for inserting table_field_id for uploading attachment
{
int intNewId = 0;
try
{
strConn = ConfigurationManager.ConnectionStrings["Ulysses"].ToString();
conn = new SqlConnection(strConn);
command = new SqlCommand(strStoredProcedureName, conn);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("@newid", SqlDbType.Int);
command.Parameters["@newid"].Direction = ParameterDirection.ReturnValue;
conn.Open();
command.ExecuteNonQuery();
intNewId = (int)command.Parameters["@newid"].Value;
}
catch (Exception ex)
{

}
finally
{
conn.Close();
conn = null;
}
return intNewId;
}
}

这是我使用的存储过程:

    SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SP_LINK_TABLE_FIELD_ID]
AS
begin tran;
declare @nextid integer;
update generator set current_number = current_number + 1 where generator = 'LINK_TABLE_FIELD';
select @nextid = current_number from generator where generator = 'LINK_TABLE_FIELD';
commit tran;
return @nextid;

我不确定为什么需要声明它,甚至其他具有相同样式的函数在代码中也没有问题,但是这个显示了这个错误。我希望任何人都可以就这个问题提供一些见解。提前致谢。

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com