我从SQL服务器获取原始varbinary数据.首先我将其保存为文件,因为我正在加载文件并在图表上绘制一系列点.但是现在我还想在用户点击按钮时将其保存到另一台服务器.这非常愚蠢:
当我可以做的时候:
我认为它需要是一个字节数组,因为我正在加载的服务器和我保存的服务器具有数据类型varbinary(max).我附上了我希望程序做什么的图像.
所以我的问题:使用BinaryWriter停止保存到路径,并开始获取一个byte []我可以使用几次
这是我认为它保存到给定文件路径的部分.
string fullPath = C:/Users/Mathias/Documents/Lektier/IHA/3. Semester/Projekt/Temporary Blob + "/" + fileName;
while (reader.Read())
{
FileStream fs = new FileStream(fullPath, FileMode.OpenOrCreate, FileAccess.Write);
BinaryWriter writer = new BinaryWriter(fs);
CurrentIndex = 0;
BytesReturned = reader.GetBytes(1, CurrentIndex, Blob, 0, BufferSize);
while (BytesReturned == BufferSize)
{
writer.Write(Blob);
writer.Flush();
CurrentIndex += BufferSize;
BytesReturned = reader.GetBytes(1, CurrentIndex, Blob, 0, BufferSize);
}
writer.Write(Blob, 0, (int)BytesReturned);
writer.Flush(); writer.Close();
}
Run Code Online (Sandbox Code Playgroud)

如果您需要此表单的完整源代码,请询问.现在它只是一种混乱,所以我没有看到粘贴整个事情的重点.
现在我正在向数据集中添加数据,然后在该数据的第一个表中选择第一行和第一行.必须有一些较短的方法吗?
SqlCommand LoadCmd = new SqlCommand("Select start_tid from EKGDATA where ekgmaaleid = @ekgmaaleid", GlobalVariables.offCon);
LoadCmd.Parameters.AddWithValue("@ekgmaaleid", maaleid);
SqlDataAdapter da = new SqlDataAdapter(LoadCmd);
DataSet ds = new DataSet();
da.Fill(ds);
string dato = Convert.ToString(ds.Tables[0].Rows[0][0]);
Run Code Online (Sandbox Code Playgroud) 我正在使用 Boost 属性树将我的类实例导出为 XML 节点。它有效,但它只是将所有内容放在 1 行中。我希望它有缩进,例如:
<?xml version="1.0" encoding="utf-8"?>
<root>
<sensorconfigurations>
<configuration>
<name>SensorConfiguration1</name>
<sensorid>1</sensorid>
<signalindex>1</signalindex>
<mappingscheme>mappingscheme1</mappingscheme>
<soundpack>test1.wav</soundpack>
</configuration>
<configuration>
<name>SensorConfiguration2</name>
<sensorid>2</sensorid>
<signalindex>2</signalindex>
<mappingscheme>mappingscheme1</mappingscheme>
<soundpack>test2.wav</soundpack>
</configuration>
<configuration>
<name>SensorConfiguration3</name>
<sensorid>3</sensorid>
<signalindex>3</signalindex>
<mappingscheme>mappingscheme2</mappingscheme>
<soundpack>test3.wav</soundpack>
</configuration>
</sensorconfigurations>
</root>
Run Code Online (Sandbox Code Playgroud)
这有可能吗?我是否缺少 write_xml 方法中的参数?
这是我的代码:
void SensorConfigurationBank::save()
{
using boost::property_tree::ptree;
ptree pt;
for(map<string, SensorConfiguration>:: iterator it = sensorConfigurations_.begin(); it != sensorConfigurations_.end(); ++it)
{
ptree myTree;
myTree.put("name", it->second.getName());
myTree.put("sensorid", it->second.getSensorID());
myTree.put("signalindex", it->second.getsignalIndex());
MappingScheme myScheme = it->second.getMScheme();
myTree.put("mappingscheme", myScheme.getId());
SoundPack mySound = it->second.getSound();
myTree.put("soundpack", mySound.filepath_);
pt.add_child("root.sensorconfigurations.configuration", myTree);
} …Run Code Online (Sandbox Code Playgroud) 我有一个在打开新表单实例时创建的线程.此表单打开时,此线程应始终运行.表单关闭后,它应该死掉.
问题是当我打开同一表单的新实例时,它使用相同的线程.
我正在寻找的正确代码可能是我正在考虑的某个方面......除非这是无效的:
t = new Task(Task.Factory.StartNew(() => totalDistance()));
Run Code Online (Sandbox Code Playgroud)
这是整个代码:方法WindowsFormClosing可能是不必要的,但我没有想法.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace ITS3_Eksamen_F2014_201270810
{
public partial class DistanceForm : Form
{
Data dat;
private string name;
Task t;
private bool killThread;
public DistanceForm(Data d, string n)
{
dat = d;
name = n;
InitializeComponent();
getDistance(name);
nameLabel.Text = name;
t = Task.Factory.StartNew(() => totalDistance());
killThread = false;
}
private void getDistance(string name)
{
var …Run Code Online (Sandbox Code Playgroud)