C# 就是面向对象的编程,所有的对象当然要实例化了 也就是 new 你看不到,不代表没有,1楼正解, 程序入口已经实例化类 ,一个对象要在其他 类或对象里 实例化 才可以显示出来,
存入SqlConnection con = new SqlConnection("Server=Darkover;uid=<username>;pwd=<strong password>;database=northwind"); SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages", con); SqlCommandBuilder MyCB = new SqlCommandBuilder(da); DataSet ds = new DataSet("MyImages");da.MissingSchemaAction = MissingSchemaAction.AddWithKey; FileStream fs = new FileStream(@"C:\winnt\Gone Fishing.BMP", FileMode.OpenOrCreate, FileAccess.Read);
byte[] MyData= new byte[fs.Length]; fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
da.Fill(ds,"MyImages");
DataRow myRow; myRow=ds.Tables["MyImages"].NewRow();myRow["Description"] = "This would be description text"; myRow["imgField"] = MyData; ds.Tables["MyImages"].Rows.Add(myRow); da.Update(ds, "MyImages");con.Close();
你看不到,不代表没有,1楼正解, 程序入口已经实例化类 ,一个对象要在其他 类或对象里 实例化 才可以显示出来,
SqlDataAdapter da = new SqlDataAdapter("Select * From MyImages", con);
SqlCommandBuilder MyCB = new SqlCommandBuilder(da);
DataSet ds = new DataSet("MyImages");da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
FileStream fs = new FileStream(@"C:\winnt\Gone Fishing.BMP", FileMode.OpenOrCreate, FileAccess.Read);
byte[] MyData= new byte[fs.Length];
fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
da.Fill(ds,"MyImages");
DataRow myRow;
myRow=ds.Tables["MyImages"].NewRow();myRow["Description"] = "This would be description text";
myRow["imgField"] = MyData;
ds.Tables["MyImages"].Rows.Add(myRow);
da.Update(ds, "MyImages");con.Close();