我的以下代码工作正常,但是如何在其中添加where子句。
一直在尝试以下字符串:
sql =“从[设备]中选择[ip_address],[name],[model],[mac_address],[operating_system],[current_user],其中[ip_address] = @ 192.168.0.56”;
using System;
using System.Data.SQLite;
using System.IO;
namespace SQLiteSamples
{
class Program
{
// Holds our connection with the database
SQLiteConnection m_dbConnection;
public string Info { get; private set; }
static void Main(string[] args)
{
Program p = new Program();
}
public Program()
{
connectToDatabase();
printResult();
}
// Creates a read only connection to spiceworks database file.
void connectToDatabase()
{
//m_dbConnection = new SQLiteConnection(@"Data Source=\\spiceworks\db\spiceworks_prod.db;Version=3;Read Only=True");
m_dbConnection = new SQLiteConnection(@"Data Source=C:\Temp\ZipSampleExtract\db\spiceworks_prod.db;Version=3;Read Only=True");
m_dbConnection.Open();
}
// Writes the output from spiceworks table devices.
void printResult()
{
string sql = "select [ip_address], [name], [model], [mac_address], [operating_system], [current_user]from [devices]";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("ip_address: " + reader["ip_address"] + " " + reader["name"] + " " + reader["model"] + " " + reader["mac_address"]+" " + reader["operating_system"] + " " + reader["current_user"]);
Info = Convert.ToString(Console.ReadLine());
File.WriteAllText("E:\\johnb.txt", Info);
}
}
}
参考方案
SQL中的字符串文字用单引号引起来:
string sql = "select [ip_address], [name], [model], [mac_address], [operating_system], [current_user] from [devices] where [ip_address] = '192.168.0.56'";
当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…
改造正在返回一个空的响应主体 - java我正在尝试使用Retrofit和Gson解析一些JSON。但是,我得到的响应机构是空的。当我尝试从对象中打印信息时,出现NullPointerException。我确保URL正确,并且我也确保POJO也正确。我正在使用jsonschema2pojo来帮助创建POJO类。这是我要解析的JSON{ "?xml": { "@versi…
每个文件合并后添加换行 - python我有很多类似以下内容的JSON文件:例如。1.json{"name": "one", "description": "testDescription...", "comment": ""} test.json{"name"…
您如何在列表内部调用一个字符串位置? - python我一直在做迷宫游戏。我首先决定制作一个迷你教程。游戏开发才刚刚开始,现在我正在尝试使其向上发展。我正在尝试更改PlayerAre变量,但是它不起作用。我试过放在列表内和列表外。maze = ["o","*","*","*","*","*",…
Mongo汇总 - javascript我的收藏中有以下文件{ "_id": ObjectId("54490b8104f7142f22ecc97f"), "title": "Sample1", "slug": "samplenews", "cat": …