在更新datagridview中的视图时,我遇到了一些问题。我的函数成功删除了数据库中的选定行,但DataAdapter没有填充数据表dt。添加行时,具有相同结构的功能非常有效。
private string ConString;
private SQLiteCommand cmd;
DataTable dt = new DataTable();
SQLiteConnection sql_con;
SQLiteDataAdapter DB;
// Function to delete rows
public void DeleteRow(string value)
{
string sqlStatement = "DELETE FROM Trades WHERE ID = " + value;
try
{
sql_con = new SQLiteConnection(ConString);
sql_con.Open();
cmd = sql_con.CreateCommand();
cmd.CommandText = sqlStatement;
cmd.ExecuteNonQuery();
DB = new SQLiteDataAdapter();
dt.Clear();
DB.Fill(dt);
}
finally
{
sql_con.Close();
}
}