???? ID: 309158 - ????? ???????: 29 ??????? 2010 - ??????: 4.0
How To Read and Write BLOB Data by Using ADO.NET with Visual C# .NET
?????? ?????? This article applies to a different operating system than the one you are using. Article content that may not be relevant to you is disabled.
The
GetChunk ??
AppendChunk methods are not available in ADO.NET on
DataReader columns,
DataSet columns, or
Command parameters. This article describes how to use Visual C# .NET to
read and write binary large object (BLOB) fields.
??????????????? ???? outlines ???????? ?????????, ??????????, ??????? ?????? ?? ?????? ??? ?? ???? ???:
Microsoft Windows 2000 Professional ???, Windows 2000 ?????, Windows 2000 ?????, ?? Windows NT 4.0 ????? ????? ???? Microsoft Visual Studio .NET Microsoft SQL Server Create the ProjectAdd a table named MyImages to your SQL Server????????? database. Include the following fields in your table:?? ?????? ?? "ID" ??? ?? ????? ?????Int . ????? ?????? ?? "?????" ?? ???VarChar ?? 50 ?? ?????? ????? ?????? ?? "ImgField" ?? ?????? . Visual Studio .NET ??? ??????? ????, ?? ?? ????? C# Windows ????????? ??? ??? ????????? ?????? ?? ????????? ???????? ????? ????? ?? ??????? ???????, Form1 ?? ???? ??? ????? ???, ??? ???????? ?? ???Button1 ???? ?? ???(?????) ?? ??????? ??? ?????? , ?? ?? ????????? ??????? ?? ???Button2 ???? ?? ???(?? ???????) ???? ??? ?????? . ??? ????? ?? ???? ??? ??? ????? ??? ??????:
using System.Data;
using System.Data.SqlClient;
using System.IO;
???-????? ????Button1 , ?? ???? ??? ????? ??? ??????Button1_Click ????? ??????????: Uid <user name="">?? ?? ???????? ???? ?? ??? ?????? ???? ?????? ??</user> ????????
{
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();
}
???-????? ????Button2 , ?? ???? ??? ????? ??? ??????Button2_Click ????? ??????????: Uid <user name="">?? ?? ???????? ???? ?? ??? ?????? ???? ?????? ??</user> ????????
{
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");
byte[] MyData= new byte[0];
da.Fill(ds, "MyImages");
DataRow myRow;
myRow=ds.Tables["MyImages"].Rows[0];
MyData = (byte[])myRow["imgField"];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
FileStream fs = new FileStream(@"C:\winnt\Gone Fishing2.BMP", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(MyData, 0,ArraySize);
fs.Close();
}
?????? ???? ?? ????????? ?? ????? ?? ??? F5 ?????? ????? ????,(?????) ?? ??????? ??? ?????? SQL ????? ??? ???, C:\WinNT\Gone Fishing.bmp, ?? ??? ???? ?? ?????? ????? ??? ????? ????,(?? ???????) ???? ??? ?????? SQL ????? ?? ???? ?? ?????? ?? ?????? ???? ????? ?? ????? ??? ???? ???? ???? ??: Microsoft ADO.NET 1.1 Microsoft Visual C# .NET 2003 Standard Edition Microsoft Visual C# .NET 2002 Standard Edition kbhowtomaster kbio kbsqlclient kbsystemdata kbmt KB309158 KbMthi
???? ?????? ???????? ??????????: ?? ???? ?? ???? ??????? ?? ????? ?? Microsoft ????-?????? ?????????? ?????? ?????? ???? ??? ??. Microsoft ???? ??? ????-???????? ?? ????-???????? ????? ?????? ?? ???? ???????? ???? ?? ???? ????? ????? ??? ?? ??? ?????? ?? ???? ???? ???? ??? ????? ??. ???????, ????-???????? ???? ????? ???? ???? ???? ???. ?????, ????????, ?????-???? ?? ??????? ?? ???????? ?? ???? ???, ???? ?? ??? ?????? ???? ???? ??? ????? ??? ?? ???? ??. Microsoft ??????? ??? ???? ?? ?????? ?? ??????????, ????????? ?? ??? ?????? ?? ???? ????? ?? ???? ???????? ?? ??? ???? ????? ?? ??? ????????? ???? ??. Microsoft ????-?????? ?????????? ?? ????? ?????? ?? ?? ??? ??.
?????????? ?? ??????? ????????? ??????? ??:
309158
(http://support.microsoft.com/kb/309158/en-us/
)
Was this information helpful?
How much effort did you personally put forth to use this article?
Tell us why and what can we do to improve this information
Thank you! Your feedback is used to help us improve our support content. For more assistance options, please visit the
Help and Support Home Page .
???? ?????? ???? ?????? ??????
??????
??? ?????? ??????? ????
???? ??????