gpt4 book ai didi

sql - 必须声明变量标量

转载 作者:行者123 更新时间:2023-12-03 08:00:43 25 4
gpt4 key购买 nike

我有此代码:

 private void btGuardar_Click(object sender, EventArgs e)
{
if (txDescrip.Text.Trim().Equals("") == false && txPath.Text.Trim().Equals("") == false)
{
try
{
byte[] imgData = getMyFileBytes(txPath.Text);
//Server connection
OleDbConnection connection = new OleDbConnection(strcx);
String q = "INSERT INTO MisImagenes (Id,CustomImage) values(@MyPath, @ImageData)";
//Initialize sql command object for insert
OleDbCommand command = new OleDbCommand(q, connection);
//We are passing original image path and image byte data as sql parameters
OleDbParameter pMyPath = new OleDbParameter("@MyPath", (object)txPath.Text);
OleDbParameter pImgData = new OleDbParameter("@ImageData", (object)imgData);
command.Parameters.Add(pMyPath);
command.Parameters.Add(pImgData);
//Open connection and execute insert query
connection.Open();
command.ExecuteNonQuery();
connection.Close();
Mensaje.aviso("Imagen Guardada :)");
//Limpiamos
clearAlta();
}
catch (Exception exc)
{
Mensaje.aviso("Something went wrong! :( " + exc.Message);
}
}
}

当我执行时,它说“必须声明标量变量“@MyPath”。” ...有什么帮助吗?求求你了,谢谢你。

我只是想通过选择图像的路径和ID描述将图像保存到我的sqlserver数据库中。我只是得到这个令人沮丧的错误

最佳答案

您应该使用“?”而不是oledb查询中的参数名称

INSERT INTO MisImagenes (Id,CustomImage) values(?, ?)

类似的问题和答案: OleDbCommand parameters order and priority

关于sql - 必须声明变量标量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17496095/

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