public void UpdateNewDataFromDGV(string name,int id)
{
string newTableNodeName = "tbl_" + name + "_node";
string newTableLineName = "tbl_" + name + "_line";
string databasePath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
string databaseFile = databasePath + @"\db_psychrometric_project.s3db";
string connString = @"Data Source=" + databaseFile + ";Version=3;";
using (SQLiteConnection connection = new SQLiteConnection(connString))
{
connection.Open();
//--Before updating table we need to find the previous tables and the update its correspoing
//name as well..
string updateTableNodeName = null;
string updateTableLineName = null;
string sql = "select * from tbl_air_handler_details where id = @id_val";
SQLiteCommand cmd1 = new SQLiteCommand(sql, connection);
cmd1.CommandType = CommandType.Text;
cmd1.Parameters.AddWithValue("@id_val", id);
SQLiteDataReader reader = null;
reader = cmd1.ExecuteReader();
while (reader.Read())
{
updateTableNodeName = reader["node_table"].ToString();
updateTableLineName = reader["line_table"].ToString();
}
// MessageBox.Show("node table" + updateTableNodeName);
//now lets alter table name
string alterTable1 = "ALTER TABLE " + updateTableNodeName + " RENAME TO " + newTableNodeName + "";
SQLiteCommand c1 = new SQLiteCommand(alterTable1, connection);
c1.ExecuteNonQuery();
string alterTable2 = "ALTER TABLE " + updateTableLineName + " RENAME TO " + newTableLineName + "";
SQLiteCommand c2 = new SQLiteCommand(alterTable2, connection);
c2.ExecuteNonQuery();
//SQLiteDataReader reader = null;
string sql_string = "update tbl_air_handler_details set name=@name_value,node_table=@node_table_value,line_table=@line_table_value where id = @id_provided;";
SQLiteCommand command = new SQLiteCommand(sql_string, connection);
command.CommandType = CommandType.Text;
command.Parameters.AddWithValue("@name_value", name);
command.Parameters.AddWithValue("@node_table_value", newTableNodeName);
command.Parameters.AddWithValue("@line_table_value", newTableLineName);
command.Parameters.AddWithValue("@id_provided", id);
//MessageBox.Show("selected value = " + cb_station_names.SelectedItem.ToString());
command.ExecuteNonQuery();
//also update the table names...
//First identify the
}
}