本文整理汇总了C#中System.Data.DataTableReader.GetBytes方法的典型用法代码示例。如果您正苦于以下问题:C# DataTableReader.GetBytes方法的具体用法?C# DataTableReader.GetBytes怎么用?C# DataTableReader.GetBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。
在下文中一共展示了DataTableReader.GetBytes方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Data.SqlClient;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
class Class1
{
[STAThread]
static void Main(string[] args)
{
TestGetBytes();
}
static private void TestGetBytes()
{
// Set up the data adapter, using information from
// the AdventureWorks sample database.
SqlDataAdapter photoAdapter = SetupDataAdapter(
"SELECT ThumbnailPhotoFileName, ThumbNailPhoto " +
"FROM Production.ProductPhoto");
// Fill the DataTable.
DataTable photoDataTable = new DataTable();
photoAdapter.Fill(photoDataTable);
using (DataTableReader reader = new DataTableReader(photoDataTable))
{
while (reader.Read())
{
String productName = null;
try
{
// Get the name of the file.
productName = reader.GetString(0);
// Get the length of the field. Pass null
// in the buffer parameter to retrieve the length
// of the data field. Ensure that the field isn't
// null before continuing.
if (reader.IsDBNull(1))
{
Console.WriteLine(productName + " is unavailable.");
}
else
{
long len = reader.GetBytes(1, 0, null, 0, 0);
// Create a buffer to hold the bytes, and then
// read the bytes from the DataTableReader.
Byte[] buffer = new Byte[len];
reader.GetBytes(1, 0, buffer, 0, (int)len);
// Create a new Bitmap object, passing the array
// of bytes to the constructor of a MemoryStream.
using (Bitmap productImage = new
Bitmap(new MemoryStream(buffer)))
{
String fileName = "C:\\" + productName;
// Save in gif format.
productImage.Save(fileName, ImageFormat.Gif);
Console.WriteLine("Successfully created " + fileName);
}
}
}
catch (Exception ex)
{
Console.WriteLine(productName + ": " + ex.Message);
}
}
}
Console.WriteLine("Press Enter to finish.");
Console.ReadLine();
}
static private SqlDataAdapter SetupDataAdapter(String sqlString)
{
// Assuming all the default settings, create a SqlDataAdapter
// working with the AdventureWorks sample database that's
// available with SQL Server.
String connectionString =
"Data Source=(local);Initial Catalog=AdventureWorks;" +
"Integrated Security=true";
return new SqlDataAdapter(sqlString, connectionString);
}
}
开发者ID:.NET开发者,项目名称:System.Data,代码行数:84,代码来源:DataTableReader.GetBytes
注:本文中的System.Data.DataTableReader.GetBytes方法示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论