c# - Can not delete row from SQLite database -
i've got little problem when trying delete row sqlite database.
i set database this:
create table if not exists patient ( patient_id integer not null primary key autoincrement, vorname varchar(100) not null,nachname varchar(100) not null,adresse varchar(100) not null,ort varchar(100) not null,plz integer not null,geburtstag date not null);
there data in there , tried delete row this:
public void deletepatientbyid(long id) { string deletequery = "delete patient patient_id="+id.tostring()+";"; sqlitecommand command = new sqlitecommand(deletequery, connection); command.executenonquery(); command.dispose(); messagebox.show("patient: " + id.tostring() + " gelöscht"); }
the problem is, vs tells me, there no such column named patient_id
. there far can see.
anyone idea might wrong here?
are pointing right file , file have table?
create file , table
string file = @"c:\testdb.sqlite"; conn = new sqliteconnection(string.format("data source={0};version=3;", file)); if (!file.exists(file)) { sqliteconnection.createfile(file); } string createtable = "create table if not exists patient ( patient_id integer not null primary key autoincrement, vorname varchar(100) not null,nachname varchar(100) not null,adresse varchar(100) not null,ort varchar(100) not null,plz integer not null,geburtstag date not null);"; conn.open(); using (sqlitecommand cmd = conn.createcommand()) { cmd.commandtext = createtable; cmd.executenonquery(); } conn.close();
delete
public void deletepatientbyid(long id) { conn.open(); using (sqlitecommand cmd = conn.createcommand()) { cmd.commandtext = string.format("delete patient patient_id={0}", id); cmd.executenonquery(); } conn.close(); messagebox.show("patient: " + id.tostring() + " gelöscht"); }
Comments
Post a Comment