【发布时间】:2017-06-09 09:34:00
【问题描述】:
前言:关于 SO 有很多与“使用 SQL 视图的 C#”相关的问题,但我还没有找到任何接近我的问题的问题。
我正在使用 C# (Visual Studio 2015) 创建 Excel 2010 插件。在后端,我需要使用 Access 2010。我在 Access 中创建了一个视图,需要传递一个参数。
我不想在command.CommandText 中输入整个查询,而是只使用视图并绑定它需要运行的单个参数
任何帮助将不胜感激
private void getJobSetpoints(int xID, int xYear)
{
//string yearTable = "tbl_points_table_" + xYear.ToString();
try
{
connection.Open();
OleDbCommand command = new OleDbCommand();
command.Connection = connection;
command.CommandText = "qry_setpoints"; //**This is wrong, I just don't know how to identify the VIEW.
command.Parameters.Add("@ID", OleDbType.Integer).Value = xID;
OleDbDataReader reader = command.ExecuteReader();
while (reader.Read())
{
//Do stuff
}
}
finally
{
connection.Close();
}
}
【问题讨论】:
-
command.CommandText = "select * from qry_setpoints"?