使用ManagedDataAccess.dll构建ExecuteScalar查询语句
时间: 2024-05-09 18:14:44 浏览: 8
好的,您可以使用以下代码示例来使用ManagedDataAccess.dll构建ExecuteScalar查询语句:
```csharp
using System;
using System.Data;
using Oracle.ManagedDataAccess.Client;
class Example
{
static void Main()
{
string constr = "User Id=<username>;Password=<password>;Data Source=<datasource>";
using (OracleConnection con = new OracleConnection(constr))
{
con.Open();
using (OracleCommand cmd = con.CreateCommand())
{
cmd.CommandText = "SELECT COUNT(*) FROM employees";
object result = cmd.ExecuteScalar();
Console.WriteLine("The number of employees is {0}", result);
}
}
}
}
```
请注意,您需要将上面的<username>,<password>和<datasource>替换为您的实际数据库详细信息。该代码执行一个简单的SELECT COUNT(*)查询,并返回结果作为标量值。您可以根据需要修改查询字符串。