0
我只是跑Visual Studio的代碼分析中使用參數,他們告訴我使用參數化查詢以下行的代碼:如何在下面的方法
using(var DA = new SQLiteDataAdapter(SQL, connectionstring))
完整的方法:
public static DataTable SelectAll(string SQL)
{
//create a string(connectionstring), filled with the connectionstring
string connectionstring = "Data Source=" + LogicDatabase.Databasename + ";Version=3;Password=" + Settings.SQLiteDatabasePassword + ";";
//create a new DataSet
DataSet DS = new DataSet();
//Give name to a SQLiteDataAdapter
//Create a new SQLiteDataAdapter and fill it with the sql query, and path of the Database.
using(var DA = new SQLiteDataAdapter(SQL, connectionstring))
{
//Clear the dataset, so we are sure it is empty, before storing items in it.
DS.Clear();
//fill the dataset from the SQLiteDataAdapter.
DA.Fill(DS);
//Fill the DataTable with the first table of the DataSet
DataTable DT = DS.Tables[0];
//return the DataTable
return DT;
}
}
如何在此代碼中實現參數?
什麼是你的SQL語句? – 2013-04-29 14:31:13
聲明是可變的,它可以是一個參數化查詢,也可以是這樣的:選擇產品ID,從產品 – Max 2013-04-29 14:32:04
產品名稱不能是參數化查詢,如果你只是傳遞一個SQL語句。你可以改變它使用'SqlLiteCommand'替代(你_can_參數添加到 – 2013-04-29 14:34:06