/// <summary> /// SQLite Insert Record /// </summary> /// <param name="data"></param> /// <returns></returns> public void AddRecord(ref VPNobject data) { using (SQLiteConnection con = new SQLiteConnection("Data Source=" + dbName)) { con.Open(); using (SQLiteCommand command = new SQLiteCommand(con)) { command.CommandText = "insert into Connections (VpnName,ServerAddress,UserName,Password,Company,Location) values(@VpnName,@ServerAddress,@UserName,@Password,@Company,@Location); " + "select last_insert_rowid();"; command.CommandType = System.Data.CommandType.Text; command.Parameters.Add(new SQLiteParameter("@VpnName", data.VpnName)); command.Parameters.Add(new SQLiteParameter("@ServerAddress", data.ServerAddress)); command.Parameters.Add(new SQLiteParameter("@UserName", data.UserName)); command.Parameters.Add(new SQLiteParameter("@Password", data.Password)); command.Parameters.Add(new SQLiteParameter("@Company", data.Company)); command.Parameters.Add(new SQLiteParameter("@Location", data.Location)); object obj = command.ExecuteScalar(); data.Id = (long)obj; } con.Close(); } }
/// <summary> /// /// </summary> /// <param name="data"></param> /// <returns>-1 an Error</returns> public int UpdateRecord(VPNobject data) { int status; using (SQLiteConnection con = new SQLiteConnection("Data Source=" + dbName)) { con.Open(); using (SQLiteCommand command = new SQLiteCommand(con)) { command.CommandText = "update Connections set VpnName=@VpnName, ServerAddress=@ServerAddress, UserName=@UserName, Password=@Password, Company=@Company, Location=@Location where Id=@Id; " + ""; command.CommandType = System.Data.CommandType.Text; command.Parameters.Add(new SQLiteParameter("@Id", data.Id)); command.Parameters.AddWithValue("@VpnName", data.VpnName); command.Parameters.AddWithValue("@ServerAddress", data.ServerAddress); command.Parameters.AddWithValue("@UserName", data.UserName); command.Parameters.AddWithValue("@Password", data.Password); command.Parameters.AddWithValue("@Company", data.Company); command.Parameters.AddWithValue("@Location", data.Location); status = command.ExecuteNonQuery(); } con.Close(); } return(status); }