Click here to Skip to main content
15,887,350 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Getting error that column does not exist. Just started learning.
Please little help?

System.Data.SQLite.SQLiteConnection sqlite_conn;
System.Data.SQLite.SQLiteCommand sqlite_cmd;
System.Data.SQLite.SQLiteDataReader sqlite_datareader;
private int sqlite_reader;


 private void button2_Click(object sender, EventArgs e)
{
sqlite_conn = new System.Data.SQLite.SQLiteConnection("Data Source=D:/main.db;Version=3;");
sqlite_conn.Open();
sqlite_cmd = sqlite_conn.CreateCommand();
sqlite_cmd.CommandText = "DELETE  FROM Table WHERE Name ="+comboBox1.Text+"";
sqlite_reader = sqlite_cmd.ExecuteNonQuery();
sqlite_conn.Close();
}


What I have tried:

Tried SELECT * FROM Table
DB works fine.
Posted
Updated 21-Sep-18 0:21am

1 solution

Try this:
C#
sqlite_cmd.CommandText = string.Format("DELETE  FROM Table WHERE Name ='{0}'", comboBox1.Text);


For further details, please see:
SQLite WHERE - Filter Rows in a Result Set[^]

Note: your code is sql injection[^] vulnerable. You have to use parameters:
C#
this.command.CommandText = "DELETE FROM Table1 WHERE Name=@param1";
this.command.CommandType = CommandType.Text;
this.command.Parameters.Add(new SQLiteParameter("@param1", comboBox1.Text));
 
Share this answer
 
v2
Comments
phil.o 21-Sep-18 6:42am    
Downvote countered. Happened a few times this morning for perfectly valid solutions.
Maciej Los 21-Sep-18 6:50am    
Thank you, Phil.
Member 13988786 21-Sep-18 18:56pm    
Many thanks !! Will carry on learning.
Maciej Los 22-Sep-18 1:15am    
You're very welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900