本文整理汇总了C#中System.Data.SqlClient.SqlCommand.GetSqlBytes方法的典型用法代码示例。如果您正苦于以下问题:C# SqlCommand.GetSqlBytes方法的具体用法?C# SqlCommand.GetSqlBytes怎么用?C# SqlCommand.GetSqlBytes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Data.SqlClient.SqlCommand
的用法示例。
在下文中一共展示了SqlCommand.GetSqlBytes方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetStream
public Stream GetStream(int id, string filename)
{
Trace.WriteLine("DBImagePlugin - GetStream");
var connectionObj = GetConnectionObj();
connectionObj.Open();
Stream stream;
using (connectionObj)
{
var sqlDataReader = new SqlCommand(imageBlobQuery, connectionObj)
{
Parameters =
{
CreateParameter("id", id, SqlDbType.Int),
CreateParameter("name", filename, SqlDbType.NVarChar)
}
}.ExecuteReader();
using (sqlDataReader)
{
if (!sqlDataReader.Read())
{
throw new FileNotFoundException("Failed to find the specified image " + id + " in the database");
}
stream = sqlDataReader.GetSqlBytes(0).Stream;
}
}
return stream;
}
示例2: button11_Click
private void button11_Click(object sender, EventArgs e)
{
try
{
string netFileName = VissimSingleton.Instance.GetInputFileName();
string workingDir = VissimSingleton.Instance.GetWorkingDirectory();
string exeDir = VissimSingleton.Instance.GetExecutionDirectory();
if (workingDir == exeDir) throw new Exception("ex");
var files = Directory.GetFiles(workingDir, "*.*", SearchOption.TopDirectoryOnly);
foreach (string fileName in files)
{
File.Delete(fileName);
}
var sb = new SqlConnectionStringBuilder();
sb.DataSource = "TOSHIBA";
sb.InitialCatalog = "VISSIM";
sb.IntegratedSecurity = true;
using (var conn = new SqlConnection(sb.ConnectionString))
{
conn.Open();
using (var reader = new SqlCommand("SELECT * FROM Files;", conn).ExecuteReader())
{
if (reader.HasRows)
{
while (reader.Read())
{
using (var fs = new FileStream(workingDir + reader.GetString(1), FileMode.Create, FileAccess.Write))
{
var bytes = reader.GetSqlBytes(3);
fs.Write(bytes.Buffer, 0, (int)bytes.Length);
}
}
}
}
}
VissimSingleton.Instance.LoadNet(workingDir + netFileName);
VissimSingleton.Instance.LoadLayout(workingDir + "vissim.ini");
}
catch (Exception ex)
{
MessageBox.Show(this, ex.Message, ex.GetType().ToString(), MessageBoxButtons.OK, MessageBoxIcon.Error);
}
}