INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

delete command with sqlite

delete command with sqlite

(OP)
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;
}

RE: delete command with sqlite

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.

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close