我创建了一个VSTO加载项项目,并希望从名为Database1的数据库中的Table1中获取数据。
单击“下一个”和“上一个”按钮以滚动浏览数据库记录。
我正在使用Access数据库。我已经成功连接到数据库,但是访问数据时代码错误。
下面是我的代码:
public partial class ThisAddIn {
private Table1 Table1; // 'Table1' error
private AdventureWorksLTDataSetTableAdapters.CustomerTableAdapter customerTableAdapter; //'' AdventureWorksLTDataSetTableAdapterserror
private System.Windows.Forms.BindingSource customerBindingSource;
private Microsoft.Office.Tools.Word.RichTextContentControl customerContentControl;
private Microsoft.Office.Tools.Word.Controls.Button button1; //'Controls' error
private Microsoft.Office.Tools.Word.Controls.Button button2; //'Controls' error
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
this.Table1 = new Table1(); // 'Table1' error
this.customerTableAdapter = new AdventureWorksLTDataSetTableAdapters.CustomerTableAdapter();
this.customerTableAdapter.Fill(this.Table1.Customer);
this.customerBindingSource = new System.Windows.Forms.BindingSource();
Word.Document currentDocument = this.Application.ActiveDocument;
Document extendedDocument = Globals.Factory.GetVstoObject(currentDocument);
extendedDocument.Paragraphs[1].Range.InsertParagraphBefore();
extendedDocument.Paragraphs[1].Range.InsertParagraphBefore();
extendedDocument.Paragraphs[1].Range.Text =
"The companies listed in the AdventureWorksLT database: \n";
extendedDocument.Paragraphs[2].Range.Text = " ";
Word.Range range1 = extendedDocument.Paragraphs[2].Range.Characters.First;
Word.Range range2 = extendedDocument.Paragraphs[2].Range.Characters.Last;
Word.Range range3 = extendedDocument.Paragraphs[1].Range.Characters.Last;
this.button1 = extendedDocument.Controls.AddButton(range1, 60, 15, "1"); //'AddButton' error
this.button1.Text = "Previous";
this.button2 = extendedDocument.Controls.AddButton(range2, 60, 15, "2"); //'AddButton' error
this.button2.Text = "Next";
this.customerContentControl = extendedDocument.Controls.AddRichTextContentControl(
range3, "richTextContentControl1");
this.customerBindingSource.DataSource = this.Table1.Customer;
this.customerContentControl.DataBindings.Add("Text", this.customerBindingSource,
"CompanyName", true, this.customerContentControl.DataBindings.DefaultDataSourceUpdateMode);
this.button1.Click += new EventHandler(button1_Click);
this.button2.Click += new EventHandler(button2_Click);
}
void button1_Click(object sender, EventArgs e)
{
this.customerBindingSource.MovePrevious();
}
void button2_Click(object sender, EventArgs e)
{
this.customerBindingSource.MoveNext();
}
private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
{
}
Here is a reference to my project
以下是一些错误消息:
Here are some error messages(https://i.stack.imgur.com/sOGlW.png)