C#向ORACLE数据库BLOB字段存入图片时报 ORA-01008: 并非所有变量都已绑定
using(conn=newOleDbConnection(connStr)){try{conn.Open();cmd=newOleDbCommand(connStr,c...
using (conn = new OleDbConnection(connStr))
{
try
{
conn.Open();
cmd=new OleDbCommand(connStr,conn);
cmd.CommandType=CommandType.Text;
cmd.CommandText = connStr;
FileStream fs = new FileStream("c:\\02.jpg", FileMode.Open,FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] aaa = new byte[fs.Length];
br.Read(aaa, 0, (int) fs.Length);
cmd.CommandText = "insert into 图片存入(图片) values(:aaa)";
cmd.Parameters.Add(new OleDbParameter("aaa",OleDbType.Binary,(int) fs.Length));
cmd.Parameters[0].Value = aaa;
cmd.ExecuteNonQuery();
br.Close();
fs.Close();
MessageBox.Show("保存成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
什么地方出了问题,跪求高手指点~! 展开
{
try
{
conn.Open();
cmd=new OleDbCommand(connStr,conn);
cmd.CommandType=CommandType.Text;
cmd.CommandText = connStr;
FileStream fs = new FileStream("c:\\02.jpg", FileMode.Open,FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
byte[] aaa = new byte[fs.Length];
br.Read(aaa, 0, (int) fs.Length);
cmd.CommandText = "insert into 图片存入(图片) values(:aaa)";
cmd.Parameters.Add(new OleDbParameter("aaa",OleDbType.Binary,(int) fs.Length));
cmd.Parameters[0].Value = aaa;
cmd.ExecuteNonQuery();
br.Close();
fs.Close();
MessageBox.Show("保存成功");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
finally
{
conn.Close();
}
}
什么地方出了问题,跪求高手指点~! 展开
1个回答
展开全部
代码:
OleDbCommand cmd = new OleDbCommand(cnnstr, con);
cmd.CommandType = CommandType.Text;
cmd.CommandText = cnnstr;
string imgPath = @"d:/image.jpg";
FileStream file = new FileStream(imgPath, FileMode.Open, FileAccess.Read);
Byte[] imgByte = new Byte[file.Length];
file.Read(imgByte, 0, imgByte.Length);
file.Close();
cmd.CommandText = " insert into imgtable(id,img ) values ('17',:img) ";
cmd.Parameters.Add("img", System.Data.OleDb.OleDbType.Binary, imgByte.Length);
cmd.Parameters[0].Value = imgByte;
连接字符串:
strConn = "Provider=OraOLEDB.Oracle;pools=true;User ID=" + uName + ";Data Source=" + linkStr + ";Password=" + uPwd + ";";
并非:Provider=MSDAORA
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询