Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete command with sqlite

Status
Not open for further replies.

fheyn

Programmer
Mar 22, 2001
198
0
0
DE
hi,
the class listed below is used to access a sqlite database.
read data from database or insert or update data works fine.delete however does not.
what I want to do is delete one record by given id from one table (where it's the primary key) and all records by given id from a second table.
on debug I see that DeleteData() removes the corresponding records correctly but the DataAdapter's Update-Method will not do so in the database.
any idea what will cause this problem. any help appreciated.
thanks in advance

public class CTableAdapter
{
public CTableAdapter(string name)
{
Name = name;
SqlCommand = new SQLiteCommand();
DataAdapter = new SQLiteDataAdapter();
Builder = new SQLiteCommandBuilder();
Dataset = new DataSet(name);
UpdateFlag = false;

}

public DataTable Load()
{
return(this.Load(Dataset.DataSetName,"select * from "+Name));
}

public DataTable Load(string datasetname, string query)
{
SqlCommand.CommandText = query;
try {
SqlConnection.Open();

DataAdapter.SelectCommand = SqlCommand;
DataAdapter.SelectCommand.Connection = SqlConnection;
DataAdapter.Fill(Dataset);
Datatable = Dataset.Tables[0];
Datatable.TableName = datasetname;
}
catch(Exception e)
{
Info = e.Message;
Datatable = null;
}
SqlConnection.Close();

Builder.DataAdapter = DataAdapter;

return(Datatable);
}

public void Delete(int id)
{
DeleteData(id);
_Update();
}

public void DeleteData(int id)
{
DataRow[] dra = Datatable.Select("ID="+id);
for (int r = 0; r < dra.Length; r++) {
Datatable.Rows.Remove(dra[r]);
}
}

private void _Update()
{
try {
SqlConnection.Open();

Builder.GetInsertCommand();
Builder.GetUpdateCommand();
Builder.GetDeleteCommand();

DataAdapter.Update(Dataset,Name);
UpdateFlag = false;
}
catch(Exception ex)
{
string s = ex.Message;
}

SqlConnection.Close();
}

public SQLiteConnection SqlConnection { get; set; }
public string Name { get; set; }
public DataSet Dataset { get; private set; }
public DataTable Datatable { get; private set; }
public string Info { get; private set; }
public bool UpdateFlag { get; set; }
private SQLiteCommand SqlCommand { get; set; }

SQLiteDataAdapter DataAdapter;
SQLiteCommandBuilder Builder;
}
 
What is DataTable? Does it issue SQL commands to SQLite? If not then you need to issue some SQL to remove the data from the database.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top