2013-04-17 19 views
3
string TheName = "David"; 
string UserTable = "INSERT INTO USER (name) values (TheName)"; 
SQLiteCommand command2 = new SQLiteCommand(UserTable, m_dbConnection); 
command2.ExecuteNonQuery(); 

我想知道是否有可能在我的SQLite表中插入变量(如TheName示例代码),如果是你怎么样能够做到吗?SQLite的,在我的表中插入变量(C#控制台应用程序)

回答

4

您需要的参数化查询:

command2.CommandText = "INSERT INTO User (name) VALUES(@param1)"; 
command2.CommandType = CommandType.Text; 
command2.Parameters.Add(new SQLiteParameter("@param1", TheName));