代码如下
this.sqlDataAdapter1.Fill(this.dataSet1,0,1,"Products");
System.IO.FileStream fs = new System.IO.FileStream(this.openFileDialog1.FileName,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
byte[] img=new Byte[fs.Length];
fs.Read(img,0,(int)fs.Length);
object[] o= new object[6];
o[0]=null;
o[1]=this.textBox_ProductName.Text;//"桔子香水";
o[2]=this.textBox_disp.Text;//"good";
o[3]=int.Parse(this.textBox_Price.Text);
o[4]=img;
o[5]=long.Parse(this.textBox_PSerial.Text);//1364;
this.dataSet1.Tables["Products"].Rows.Add(o);
this.sqlDataAdapter1.Update(this.dataSet1,"Products");
MessageBox.Show("Insert Over");
this.sqlDataAdapter1.Fill(this.dataSet1,0,1,"Products");
System.IO.FileStream fs = new System.IO.FileStream(this.openFileDialog1.FileName,System.IO.FileMode.Open,System.IO.FileAccess.Read,System.IO.FileShare.Read);
byte[] img=new Byte[fs.Length];
fs.Read(img,0,(int)fs.Length);
object[] o= new object[6];
o[0]=null;
o[1]=this.textBox_ProductName.Text;//"桔子香水";
o[2]=this.textBox_disp.Text;//"good";
o[3]=int.Parse(this.textBox_Price.Text);
o[4]=img;
o[5]=long.Parse(this.textBox_PSerial.Text);//1364;
this.dataSet1.Tables["Products"].Rows.Add(o);
this.sqlDataAdapter1.Update(this.dataSet1,"Products");
MessageBox.Show("Insert Over");
解决方案 »
- GroupBox的标题居中或居右
- 用linq 获取字典value为最大的那条数据,包含key和value,该怎么做
- 正则表达式问题,急!
- enterprise library 执行oracle语句?
- 求一本学习【C#】好的教材!
- comboBox出现了问题了!!代码如下!!!高手快点帮忙啊
- 请教:(三楼楼长)的OA问题,我安装以后可以运行,但是无法打开和编辑。打开项目时要求输入用户名口令,然后显示:您没有修改这篇文档的权
- Timer的Elapsed中抛出异常,谁来接?
- DataSet 问题
- 请 请 请。。。。。。。。。。。。。。
- 为什么在datagrid中修改数据时不会引起RowChanging或ColumnChanging事件?
- C#入门级问题!!!
中添加<httpRuntime executionTimeout="90" maxRequestLength="100000" useFullyQualifiedRedirectUrl="false" />
Power(2,Power(2,16))
是2的64K次方
SQL SERVER的16字节不是存放数据大小,而是存放数据的位置地方~~~
你的Object[]可能限制了大小,试试下面的代码:string sSql = "insert into table_image values('ID_1',@byteImage)";
SqlCommand mCom = new SqlCommand(sSql,xCon);
Byte[] btyData = ...;
SqlParameter mySqlParam =
new SqlParameter("@byteImage", SqlDbType.VarBinary, btyData.Length, ParameterDirection.Input, false,0,0,null,DataRowVersion.Current,btyData);这样就能自己指定Byte[]的长度
private int insert(string filename, byte[] buffer){
string connstr="server=;uid=sa;pwd=;database=tec";
SqlConnection conn=new SqlConnection(connstr);
SqlCommand cmd =new SqlCommand("ins_image",conn);
cmd.CommandType=CommandType.StoredProcedure;
SqlParameter name= new SqlParameter("@name",SqlDbType.VarChar,50);
name.Direction=ParameterDirection.Input;
name.Value=filename;
cmd.Parameters.Add(name);
SqlParameter pic= new SqlParameter("@pic",SqlDbType.Image,16);
pic.Direction=ParameterDirection.Input;
pic.Value=buffer;
cmd.Parameters.Add(pic);
conn.Open();
int i=cmd.ExecuteNonQuery();
conn.Close();
return i;
}CREATE PROCEDURE [ins_image]
( @name [varchar](50),
@pic [image])
AS INSERT INTO [tec].[dbo].[image]
( [name],
[pic])
VALUES
( @name,
@pic)
GO
不可以。 这可能和SqlDataAdapter的局限性有关。 所以我使用tshill(hill) 和 fengyuyan(风雨岩) 的方法都成功了。Image类型存储的只是一个指针,这个问题不是他的错。现在结贴,谢谢各位!