C#调用Bartender 连TXT文件出错 A database with the name "TextfileDatabase" does not exis

ZHANGWENDY 2011-05-24 11:02:19
目的:在数据库中设定标签格式,及定义的Substring设定值类型。
再通过给定义的文件路径及格式,打印。
版本:9.4
代码如下:
if (!File.Exists(filepath))
{
MessageBox.Show("打印文件不存在!", "警告", MessageBoxButtons.OK);
return;
}

string connstr = "";

try
{
engine = new Engine();
engine.Start();
LabelFormatDocument btFormat = engine.Documents.Open(FormPath);
btFormat.PrintSetup.PrinterName = printName;

// Assign number of identical copies if it is not datasourced.
if (!(printCopies >= 1))
MessageBox.Show("Warning", "Copies must be an integer greater than or equal

to 1.", MessageBoxButtons.OK);
else
btFormat.PrintSetup.IdenticalCopiesOfLabel = printCopies;
//连接txt文件作为数据库
TextFile textFileDB = new TextFile("TextfileDatabase");
textFileDB.FileName = filepath;
btFormat.DatabaseConnections.SetDatabaseConnection(textFileDB);

//取文件名作为数据库域名称
string filename = print_set_header.Rows[0]["FORMAT_NAME"].ToString() ;
filename = filename.Replace(".btw", "");

//根据标签Substring取值类型赋值
for (int i = 0; i < print_set_detail.Rows.Count; i++)
{
//指定文字
if ("T".Equals(print_set_detail.Rows[i]["TYPE"].ToString(),

StringComparison.CurrentCultureIgnoreCase))
{
btFormat.SubStrings[print_set_detail.Rows[i]["VARIABLE"].ToString

()].Value = print_set_detail.Rows[i]["COL"].ToString();
}
else
//数据库字段
{
btFormat.SubStrings[print_set_detail.Rows[i]["VARIABLE"].ToString

()].Value = filename +"."+ Convert.ToInt32(print_set_detail.Rows[i]["COL"]).ToString();
}
}
btFormat.Print();

btFormat.Close(SaveOptions.DoNotSaveChanges);
engine.Stop();
engine.Dispose();
}
catch (PrintEngineException exception)
{
// If the engine is unable to start, a PrintEngineException will be thrown.
MessageBox.Show("Warning", exception.Message, MessageBoxButtons.OK);
//this.Close(); // Close this app. We cannot run without connection to an engine.
return;
}

在以下代码处报错:
btFormat.DatabaseConnections.SetDatabaseConnection(textFileDB);
错误提示为:
A database with the name "TextfileDatabase" does not exist.
...全文
568 1 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
wayne2082 2012-02-10
  • 打赏
  • 举报
回复
是因为你设计的标签中,没有把数据库名称改为TextfileDatabase,改成一样的就好了,在标签设计中改。

111,097

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧