下面是我的 Select * Function 的代码 - 它运行良好并且一切正常,直到我将 SQL 字符串从Select *
From Company更改为
query = "Select * From @1";
然后执行以下操作
query = "Select * From @1";
OleDbCommand Command = new OleDbCommand(query, sqlConnStr);
DataTable Table = new DataTable();
DataSet dataSet = new DataSet();
Table = null;
//Add Parameters
Command.Parameters.AddWithValue("@1", SQLTables.Company);
try
{
Command.ExecuteNonQuery();
adapter.SelectCommand = Command;
adapter.Fill(dataSet);
Table = dataSet.Tables[0];
}
catch (Exception e)
{
MessageBox.Show("A Error occured whilst trying to execute the command.\n" + e.Message);
}
return Table;
DBMS 不断发回“查询不完整” - 我假设Command
变量正在发送字符串query
而不将参数从更改@1
为Company
这是一段代码(我的),它确实有效。这是一个插入语句,而不是一个选择 - 如果我错了,请纠正我,但它也不能与 SELECT 一起使用
private void MainActionsInsert(string Action, bool Checked)
{
OleDbCommand Command = new OleDbCommand("INSERT INTO MainActions Values (ID, Action, BoolValue)", DataBaseConnection);
//Add Parameters
Command.Parameters.AddWithValue("ID", GenerateID());
Command.Parameters.AddWithValue("Action", Action);
Command.Parameters.AddWithValue("BoolValue",Checked);
//Add Command
MainActionsAdapter.InsertCommand = Command;
//Execute Agains DataBase
Command.ExecuteNonQuery();
//Accept Changes
}
`