Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ms-access/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C中将ACCESS数据库中的值设置为标签#_C#_Ms Access_Oledbconnection - Fatal编程技术网

C# 在C中将ACCESS数据库中的值设置为标签#

C# 在C中将ACCESS数据库中的值设置为标签#,c#,ms-access,oledbconnection,C#,Ms Access,Oledbconnection,我想将Access数据库中的数据添加到标签。使用FORM1上的查询搜索数据 OleDbConnection connection = new OleDbConnection(); connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Ty\Documents\Uni\Level6\Project\App\software\Databases\Boards.accdb;Persi

我想将Access数据库中的数据添加到
标签
。使用
FORM1
上的查询搜索数据

OleDbConnection connection = new OleDbConnection();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Ty\Documents\Uni\Level6\Project\App\software\Databases\Boards.accdb;Persist Security Info=False;";
connection.Open();
OleDbCommand commandBoards = new OleDbCommand();
commandBoards.Connection = connection;
string queryBoardsLength = "select * from [Boards] where [Length] >=" + TxtLength.Text;
string queryBoardsWidth = "select * from [Boards] where [Width] >=" + TxtWidth.Text;
commandBoards.CommandText = queryBoardsLength;
commandBoards.CommandText = queryBoardsWidth;
OleDbDataReader readerBoards = commandBoards.ExecuteReader();

while (readerBoards.Read())
{
    ComBoards.Items.Add(readerBoards["ID"].ToString());
}
这将使用搜索结果填充
FORM1
上的组合框。然后,当选择组合框时,我将其设置为变量

private void ComBoards_SelectedIndexChanged(object sender, EventArgs e)
{
    Boards = this.ComBoards.GetItemText(this.ComBoards.SelectedItem);
}
FORM2
上,我运行了一个类似的查询,根据所选
ID
从Access数据库收集准确的数据。我想将长度显示为
标签

private void Form2_Load(object sender, EventArgs e)
{
    lblBoardname.Text = Form1.Boards;
    OleDbConnection connectionBoards = new OleDbConnection();
    connectionBoards.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Ty\Documents\Uni\Level6\Project\App\software\Databases\Boards.accdb;Persist Security Info=False;";
    connectionBoards.Open();
    OleDbCommand commandBoardsget = new OleDbCommand();
    commandBoardsget.Connection = connectionBoards;
    string queryBoardsget = "select * from [Boards] where [ID] =" + lblBoardname;
    commandBoardsget.CommandText = queryBoardsget;
    OleDbDataReader readerBoardsget = commandBoardsget.ExecuteReader();
    while (readerBoardsget.Read())
    {
        lblBoardsizel.Text = readerBoardsget["Length"].ToString();
    }
除了
FORM2
上的
读卡器
之外,所有功能都正常工作,在那里我得到以下错误:

查询表达式“[ID]=System.Windows.Forms.Label,文本:Rhino Boards”中存在语法错误(逗号)


我真的很感谢你的帮助。谢谢。

我不确定您是否能理解这条评论。如果可以,请阅读错误消息,它清楚地表明您正在传递整个label对象,而不是它的文本值。[ID]=“+LBoardName;应为[ID]=”+LBoardName.Text;嗨,谢谢你发现。。。简单的错误。然而,我仍然得到和错误。“查询表达式'[ID]=Rhino Boards'中的语法错误(缺少运算符)”